On Tuesday 18 December 2007 01:31:59 Cristian Baboi wrote: > A few days ago, for various reasons, I've started to look at Haskell. > At first I was quite impressed, after reading some FAQ, and some tutorials. > Evrything was nice and easy ... until I've started writing some code on my > own. > > What I should have been told about upfront: > > - the syntax for an expression > - the syntax for a block > - the adhoc syntax rules (how to distinguish among a tuple and a > pharanthesized expression and how to find the start and end of a block for > example ) > > - the fact that lambda expressions are not the same thing as "algebraic > data" values > - what guarantees are made by the LANGUAGE that an IO action (such as do > putStrLn "Hello world" ) is not performed twice > - the lambda expressions can be written (input) but cannot be printed > (output) > > The biggest problem for me, so far, is the last one. > > Here is some strange example: > > module Hugs where > > aa::Int > aa=7 > > cc:: (Int->Int)->(Int->Int->Int)->Int->(Int->Int) > cc a op b = \x-> case x of { _ | x==aa -> x+1 ; _-> a x `op` b } > > f::Int->Int > f(1)=1 > f(2)=2 > f(_)=3 > > g::Int->Int > g(1)=13 > g(2)=23 > g(_)=33 > > h::[Int->Int] -> Int ->Int > h [] x = x > h [rr] x = let { u=Hugs.f ; v=Hugs.g } in case rr of { u -> > Hugs.g(x)+aa ; v -> Hugs.f(x)+aa ; _ ->rr (x) + aa } > h (rr:ll) x = h [rr] x + h (ll) x > > > What I don't understand is why I'm forced to use guards like x==aa in cc, > when aa is clearly bounded (is 7) and why in function h, the bounded u and > v become free variables in the case expression.
I don't think anyone has mentioned it yet, so I'll go ahead. Many of the questions you ask are well covered by the Haskell Report: http://haskell.org/onlinereport/ The report is terse, but quite usable as a reference. Moreover, it is The Final Word on all these semantic and syntactic questions. Cheers, Spencer Janssen _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe