Re: Just for your fun and horror

Matthias Felleisen wrote:
When a C programmer thinks about the 'return' type of a C function, he thinks about the value-return half of a return statement's denotation. The other half, the modified store, remains entirely implicit as far as types are concerned.
Just because the type system of C keeps store implicit, it doesn't change the match between the meaning of 'return' in the two languages. The IO monad provides a refined way of typing imperative-style functions, including return statements. If you want to use a return statement in Haskell, you can, and it's called 'return'. (A reasonable alternative would be for 'return' to have second class status, as syntactic sugar for 'unit', analgous to otherwise=True). -- Scott Turner p.turner@computer.org http://www.billygoat.org/pkturner

On Fri, 16 Feb 2001, Scott Turner wrote:
Just because the type system of C keeps store implicit, it doesn't change the match between the meaning of 'return' in the two languages.
Or to put it another way, _all_ types in C are IO something. I think from a didactic point of view making this observation could be very valuable. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk 31 Chalmers Road jf@cl.cam.ac.uk Cambridge CB1 3SZ +44 1223 570179 (pm only, please)

Jon Fairbairn
On Fri, 16 Feb 2001, Scott Turner wrote:
Just because the type system of C keeps store implicit, it doesn't change the match between the meaning of 'return' in the two languages.
Or to put it another way, _all_ types in C are IO something. I think from a didactic point of view making this observation could be very valuable.
I absolutely agree. The Haskell foo :: IO Int foo = return 42 and C int foo () { return 42; } are exactly the same. It is bar = 42 for which C has no corresponding phrase. So, it is a new concept, which for the students - not surprisingly - is an intellectual challenge. In fact, I think, there is a second lesson in the whole story, too: Syntax is just...well...syntax. Students knowing only one or possibly two related languages, often cannot distinguish between syntax and semantics. Breaking their current, misguided model of programming languages is a first step for them towards gaining a deeper understanding. So, `return' is a feature, not a bug. I guess, the remedy for the course would be to provoke a discussion of the issue of C's return versus Haskell's return before the exam. Cheers, Manuel
participants (4)
-
Jon Fairbairn
-
Manuel M. T. Chakravarty
-
Scott Turner
-
Sebastien Carlier