🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #522

Re: Implementing Error Values

#522
From: Mike Fourman
Date: Fri, 23 Nov 1990 16:09
44 lines
2314 bytes
In article <88@syrian.cs.utexas.edu> emery@cs.utexas.edu (Emery Berger) writes:
>In article <86438@lll-winken.LLNL.GOV> you write that you want to
>know how to accomplish the following in a functional language:
>
>>Example: (plus (div a 0) (plus b c))	;;; [ (a/0) + (b+c) ]
>>	 
>>	 The value of (div a 0) is ERROR.
>>	 Therefore the value of (plus (div a 0) (plus b c))
>>	 is also ERROR.
>>
>
>   This is pretty straightforward in Miranda.
>
>result ::= Val num | ERROR
>
[stuff deleted]

However, this solution won't allow you to propagate errors through 
arbitrary function calls (because of the type system). In standard 
ML there is an exception mechanism that allows errors to be raised
and handled, and lets them carry values if you wish.

> 1 div 0; (* exceptions can be raised *)
Exception- Div raised
Exception failure raised
>  (1 div 0) + (3 div 4) ;  (* exceptions propagate *)
Exception- Div raised
Exception failure raised
> ((1 div 0) handle Div => 1000) + (3 div 4) ;(* exceptions can be handled *)
val it = 1000 : int   
> ( (1 div 0) + (3 div 4) ) handle Div => 42 ;(* exceptions can be handled later *)
val it = 42 : int   
> real ;
val it = fn : int -> real   
> real ( 1 div 0 ); (* exceptions propagate even when types change *)
Exception- Div raised
Exception failure raised


--
Prof. Michael P. Fourman                      email        mikef@lfcs.ed.ac.uk
Dept. of Computer Science                     'PHONE (+44) (0)31-650 5198 (sec)
JCMB, King's Buildings                               (+44) (0)31-650 5197
Mayfield Road, Edinburgh EH9 3JZ, Scotland, UK FAX   (+44) (0)31 667 7209
Technical Details
Message-ID: <2437@skye.cs.ed.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!mikef
References: <86438@lll-winken.LLNL.GOV> <88@syrian.cs.utexas.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!mikef
From: mikef@cs.ed.ac.uk (Mike Fourman)
Newsgroups: comp.lang.functional
Subject: Re: Implementing Error Values
Keywords: pointers, papers, paraphernalia, error values, implementation
Message-ID: <2437@skye.cs.ed.ac.uk>
Date: 23 Nov 90 16:09:52 GMT
References: <86438@lll-winken.LLNL.GOV> <88@syrian.cs.utexas.edu>
Sender: nnews@cs.ed.ac.uk
Reply-To: mikef@lfcs.ed.ac.uk (Mike Fourman)
Organization: Laboratory for the Foundations of Computer Science, Edinburgh U
Lines: 44