Thanks all.

I have now this :

-- | The main entry point.
last' :: [a] -> Maybe a
last' [] = Nothing
last' [x] = Just x
last' (_:xs) = last' xs


main = print . last' [1,2,3]

but I see this message about main :

GHC threw an exception : Couldn't match expected type ‘GHC.Types.IO a0’ with actual type ‘a1 -> GHC.Types.IO ()’

I work wih the fpcomplete and they demand a main in the code .

Roelof




Nicolas SCHOEMAEKER schreef op 12-5-2015 om 11:45:

Hi

In your definition, you seem to have forgotten the case when your list is empty.
[x] won't bind on [].

Regards,
Nicolas SCHOEMAEKER

(This email was composed from a mobile phone, please excuse any resulting mistakes)

Web, Cloud Computing & WebRTC developer
Haskell Programmer
Artificial Intelligence & Robotics enthusiast

On May 12, 2015, at 11:40 AM, Kim-Ee Yeoh <ky3@atamo.com> wrote:

On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben <r.wobben@home.nl> wrote:

-- | The main entry point.
last' :: [a] -> a
last' [x] = x
last' (x:xs) = last xs

Notice that the last line does no recursion: it invokes the Prelude's definition of last.

-- Kim-Ee

Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




Avast logo

Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
www.avast.com