
Greetings, 1) How does one model "out of memory" condition in Haskell, perhaps using a Maybe type? 2) Could you give an intutive description of data construction, and how it relates to lamda calculus? Thanks

On Sun, 2 Mar 2003 10:16:12 +0200
"Cagdas Ozgenc"
Could you give an intutive description of data construction
In some form of typed lambda-calculus, you have the sum and product types. An example is PCF; see for example: http://citeseer.nj.nec.com/howard90operational.html Vincenzo

On Sun, 2 Mar 2003 10:16:12 +0200
"Cagdas Ozgenc"
Greetings,
1) How does one model "out of memory" condition in Haskell, perhaps using a Maybe type?
Unfortuntely not since it would not be referentially transparent. It's part of a more general issue of exceptions in pure code. You can't have calculateSomething :: X -> Maybe Y Such that it returns Nothing if it ran out of memory. You can do it in the IO monad, which is the standard technique: doCalculateSomething :: X -> IO (Maybe Y) doCalculateSomething x = catchJust asyncExceptions (evaluate $ Just $ calculateSomething x) handleOOM where handleOOM StackOverflow = return Nothing --return nothing if out of memory handleOOM HeapOverflow = return Nothing handleOOM otherException = ioError otherException Probably the thing to do is just catch the exceptions rather than have your functions return Maybe types. That way you don't have to deal with Maybes all over the place. See the paper on asynchronous exceptions which mentions treating out of memory conditions as an asynchronous exception: http://research.microsoft.com/Users/simonpj/Papers/asynch-exns.htm BTW HeapOverflow doesn't actually work yet according to the ghc documentation. Duncan

Greetings,
1) How does one model "out of memory" condition in Haskell, perhaps using a Maybe type?
Unfortuntely not since it would not be referentially transparent. It's part of a more general issue of exceptions in pure code.
You can't have
calculateSomething :: X -> Maybe Y
Such that it returns Nothing if it ran out of memory.
<snip>
Probably the thing to do is just catch the exceptions rather than have your functions return Maybe types. That way you don't have to deal with Maybes all over the place.
Does this make the use of Monads doubtful? I mean it doesn't seem easy to have a completely pure language, and the time one starts introducing few impurities one also starts thinking why not include many others? Just a thought...

Does this make the use of Monads doubtful? I mean it doesn't seem easy to have a completely pure language, and the time one starts introducing few impurities one also starts thinking why not include many others?
I suggest that you read this paper: A semantics for imprecise exceptions, Peyton-Jones et al. You can find a copy on the documentation page for GHC: http://haskell.cs.yale.edu/ghc/ See also: Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell, Peyton-Jones. You can find it here: http://citeseer.nj.nec.com/peytonjones00tackling.html Cheers, Bernie.
participants (4)
-
Bernard James POPE
-
Cagdas Ozgenc
-
Duncan Coutts
-
Nick Name