[Haskell-beginners] where do i get wrong

Nadir Sampaoli nadirsampaoli at gmail.com
Sun Mar 2 20:36:33 UTC 2014


Hello,

2014-03-02 20:50 GMT+01:00 Roelof Wobben <r.wobben at home.nl>:

>  Correect, I forget to use map
> But also x = map "aBCde".islower does not work.
>
> Your use of the dot (.) function makes me think you might mix Haskell
syntax with OO languages like Python or Java where dot notation is used to
call methods on objects.

Also, as Emanuel and Vlatko pointed out one very important thing in Haskell
is reading type signatures. So, let's check `map` signature:

    map :: (a -> b) -> [a] -> [b]

What does this mean?
Although all Haskell functions take one and only one argument we probably
might find it simpler to reason in terms of first argument, second argument
and return value (`map` should probably be better described as a function
that takes a function from `a` to `b` and returns a function from [a] to
[b]).

Anyway.

The first argument is (a -> b), a function from `a` to `b`.
The second argument is [a], i.e. a list of `a` (`a` can potentially
represent any type).
The last type in the signature is [b] which we might call the return type.
Again, haskellers, don't stab me please :)

Now check the type signature for `isLower`:

    isLower :: Char -> Bool

`isLower` will be `map`'s first argument, so, replacing the original (a ->
b) with isLower type signature, you'll get:

    map :: (Char -> Bool) -> [Char] -> [Bool]

A step further, the signature then becomes:

    map isLower :: [Char] -> [Bool]

As you can see here, understanding that all functions in Haskell takes just
one argument helps because `map isLower` is in turn a function. The result
of calling `map` with `isLower` as its (first and only) argument, is a
function from [a], or, better, from [Char], since Char is the (first and
only) argument of `isLower`, to [b], or, better, to [Bool] since Bool is
the return type of `isLower`.

Now we have map isLower which takes a [Char]. [Char] and String are
synonyms, by the way, so you could also write `map isLower` signature as
follows:

    map isLower :: String -> [Bool]

This seems exactly what we need: a function from String to a list of
booleans.

 I think I have to find out how I can ghci in fpcomplete or use another IDE
> which supports it.
>
> Roelof
>

Have you read/are you reading "Learn you a Haskell" (
http://learnyouahaskell.com/chapters)? I'd advise you to read it, as it
helps you, in the beginning, being more confortable with Haskell's syntax
and library.

--
Nadir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140302/7e5fbe98/attachment.html>


More information about the Beginners mailing list