Article View: comp.lang.functional
Article #523Re: Implementing Error Values
From: Nick Rothwell
Date: Fri, 23 Nov 1990 16:53
Date: Fri, 23 Nov 1990 16:53
47 lines
2480 bytes
2480 bytes
In article <2437@skye.cs.ed.ac.uk>, mikef@cs.ed.ac.uk (Mike Fourman) writes: > > 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. Way back when I implemented a functional language for my Ph.D., I had a polymorphic type system (ML-like, essentially), but I had error values as well. These carried the same types as ordinary values, but were distinguished from them for the purposes of the primitive operations (arithmetic and so on) and decomposition for pattern matching. Thus (assuming modern ML syntax): - val x = 1/0; x = <error: DIV> : int - val y = x + 1; y = <error: ADD, DIV> : int - val z = let val x :: y = nil in x end; z = <error: MATCH> : 'a - fun isError <error: _> = true | isError _ = false; isError = fn : 'a -> bool - (isError z, isError 3); (true, false) : bool * bool The only problem I could see with the scheme (and didn't have time to investigate) was that normally complete pattern matches (such as nil vs. hd :: tl) were no longer so, and it wasn't clear that termination of sensible functions could be guaranteed (a length-of-list function called with an error value would probably loop indefinitely, for example...) -- Nick Rothwell, Laboratory for Foundations of Computer Science, Edinburgh. nick@lfcs.ed.ac.uk <Atlantic Ocean>!mcsun!ukc!lfcs!nick ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ "You ain't seen nothing yet. I can take this floor out too, no trouble."
Technical Details
Message-ID:
<2442@skye.cs.ed.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!cs.edinburgh.ac.uk!nickReferences:
<86438@lll-winken.LLNL.GOV> <88@syrian.cs.utexas.edu> <2437@skye.cs.ed.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!cs.edinburgh.ac.uk!nick From: nick@cs.edinburgh.ac.uk (Nick Rothwell) Newsgroups: comp.lang.functional Subject: Re: Implementing Error Values Keywords: pointers, papers, paraphernalia, error values, implementation Message-ID: <2442@skye.cs.ed.ac.uk> Date: 23 Nov 90 16:53:49 GMT References: <86438@lll-winken.LLNL.GOV> <88@syrian.cs.utexas.edu> <2437@skye.cs.ed.ac.uk> Sender: nnews@cs.ed.ac.uk Reply-To: nick@lfcs.ed.ac.uk Organization: Wavetables 'R' Us Lines: 47