modeling out of memory
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
is identity the only polymorphic function without typeclasses?
Greetings, Is identity function the only meaningful function one can write without constraining the type variable using a typeclass? If not, could you please give a counter-example? Thanks
Re: is identity the only polymorphic function without typeclasses?
G'day all. On Sun, Mar 02, 2003 at 10:18:13AM +0200, Cagdas Ozgenc wrote: Is identity function the only meaningful function one can write without constraining the type variable using a typeclass? If not, could you please give a counter-example? This might help: @incollection{ wadler89theorems, author = Philip Wadler, title = Theorems for Free!, booktitle = Proceedings 4th Int.\ Conf.\ on Funct.\ Prog.\ Languages and Computer Arch., {FPCA}'89, London, {UK}, 11--13 Sept 1989, publisher = ACM Press, address = New York, pages = 347--359, year = 1989 } Cheers, Andrew Bromage ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: modeling out of memory
On Sun, 2 Mar 2003 10:16:12 +0200 Cagdas Ozgenc [EMAIL PROTECTED] wrote: 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 ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: is identity the only polymorphic function without typeclasses?
Cagdas Ozgenc [EMAIL PROTECTED] wrote: Greetings, Is identity function the only meaningful function one can write without constraining the type variable using a typeclass? If not, could you please give a counter-example? Certainly you can write lots of ``meaningful function''s without type classes: not, (), (||), as well as many more complicated functions at more complicated types. You can also write useful polymorphic functions without type classes, as long as you specify at least one type. For example, you can write polymorphic functions over/yielding lists, such as repeat, cycle, map and its many relatives, foldr and its many relatives, take and its relatives, takeWhile and its relatives, etc. Similar functions often exist for other types. I'm somewhat curious, though: why do you ask this question? How do you expand your question that makes the answer seem to be ``no''? Thanks Jon Cast ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe