Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Pound character use in code? (M.v.Gulik)


----------------------------------------------------------------------

Message: 1
Date: Tue, 23 Oct 2012 10:31:56 +0200
From: "M.v.Gulik" <[email protected]>
Subject: [Haskell-beginners] Pound character use in code?
To: "[email protected]" <[email protected]>
Message-ID:
        <caospiufcnsvvhtdeqttbqmvgbn9ecnpjwyzh9famvfczb02...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi

Trying to learn a bit about Haskell as general (script) coder (batch,
autoit, python).
And run into some code I don't get. (could not find the right online
doc that explained it.)

[Code]
length'                  :: [a] -> Int
length' l                =  len l 0#
        where
                len :: [a] -> Int# -> Int
                len []     a# = I# a#
                len (_:xs) a# = len xs (a# +# 1#)

[/Code]
source: 
http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-List.html#length

1) What is the purpose of the used pound/"#" character here. (Looks
like some type-casting, but that's just a wild guess from me here.
(I'm not a C~ or Java coder))

2) kinda the same for the "I#" in the "len [] ..." line. As the length
function takes only one return result. (note: its a capital i and not
a lowercase L.)

3) Why is it giving a compile error on the "where" line. Error:
"Haskell\baby.hs:<lineNr>:9: parse error on input `where'" (while the
adjusted code below compiles fine. Tab(4s) indented.)

[Code]
length'                  :: [a] -> Int
length' l                =  len l 0
        where
                len :: [a] -> Int -> Int
                len []     a = a
                len (_:xs) a = len xs (a + 1)
[/Code]

Using: WinGHCi 1.0.6 on Windows Xp. (Haskell Platform 2012.2.0.0
windows install)

TIA
MvGulik



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 52, Issue 27
*****************************************

Reply via email to