[Haskell-beginners] Utter Newbie - simple problems,
output - GHC vs GHCi
Nigel Rantor
wiggly at wiggly.org
Sun Aug 30 18:09:41 EDT 2009
I am trying to get my head around Haskell but seem to keep butting
against problems that have nothing to do with FP yet, but are simply to
do with not understanding the tools.
I've been trying a lot of code from multiple tutorials but I keep
finding that the code simply does not work out of the box, and requires
some other setup I am unaware of.
I am currently on Debian, using GHC 6.8.2 installed using apt, so I
assume that the toolchain is installed and working correctly.
For example, the most recent tutorial I've been looking at is the "yet
another haskell tutorial", here -
http://www.cs.utah.edu/~hal/docs/daume02yaht.pdf
One of the exercises after talking about functions that act on lists is
to determine the number of lowercase letters in a string.
Fine, that makes complete sense to me. I figure something along the
lines of:
length( filter( Char.isLower "LoweR" ) )
should return the value 3
If I attempt this at the interactive GHC prompt I get the following:
------------------------------------------------------------------------------------------
wiggly at mink:~/src/ht$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
Prelude> show( length( filter( Char.isLower "LoweR" ) ) )
<interactive>:1:35:
Couldn't match expected type `Char' against inferred type `[Char]'
In the first argument of `GHC.Unicode.isLower', namely `"LoweR"'
In the first argument of `filter', namely
`(GHC.Unicode.isLower "LoweR")'
In the first argument of `length', namely
`(filter (GHC.Unicode.isLower "LoweR"))'
Prelude>
------------------------------------------------------------------------------------------
If I attempt to put the code into a file and compile it I get the following:
[Code]
------------------------------------------------------------------------------------------
module Main where
import Char
main = show( length( filter( Char.isLower "LoweR" ) ) )
------------------------------------------------------------------------------------------
[Terminal]
------------------------------------------------------------------------------------------
wiggly at mink:~/src/ht$ ghc -o test ex3.hs
ex3.hs:3:42:
Couldn't match expected type `Char' against inferred type `[Char]'
In the first argument of `isLower', namely `"LoweR"'
In the first argument of `filter', namely `(isLower "LoweR")'
In the first argument of `length', namely
`(filter (isLower "LoweR"))'
wiggly at mink:~/src/ht$
------------------------------------------------------------------------------------------
This is one of the smallest examples I can think of posting for some
help, and quite frankly, I'm feeling a bit dim because I just cannot
understand why this doesn't work...I've tried in vain to mess with the
code (I won't attempt to describe it, I'm not au fait enough with
Haskell terminology yet, it would sound like gibberish *and* be incorrect)
Any help would be awesome, equally, any ready-to-run examples/tutorials
that people could recommend would likewise be awesome and beer-worthy[0].
Cheers,
n
[0] offer only applies to those in the London area or those environs
where I find myself randomly
More information about the Beginners
mailing list