[Haskell-cafe] New to Haskell

Cristian Baboi cristi at ot.onrc.ro
Tue Dec 18 02:31:59 EST 2007


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.





________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
  part000.txt - is OK
http://www.eset.com


More information about the Haskell-Cafe mailing list