Hello,

Im now trying to make a rfold solution to this problem.

Till now I have this :

last5 :: [a] -> Maybe a
last5 xs = foldr acc initial xs

acc :: a -> Maybe a -> Maybe a
acc x y = where
    acc x Nothing  = Just x
    acc _ j        = j

initial :: Maybe a
initial = Nothing

So still not working.

Can someone explain to me in small steps how to figure out what the right answer is to the acc part.

Roelof




Roelof Wobben schreef op 11-11-2014 8:20:
Thanks, this is working well.

But just for understanding

in the part acc x Nothing   x is the input string,
and in the part _j means the same as (xs:x)

Roelof
 


Alex Hammel schreef op 10-11-2014 22:47:
It's an indentation issue. Make sure that there are no spaces before the bit about 'last5 = foldr acc' etc.

On Mon, Nov 10, 2014 at 12:48 PM, Roelof Wobben <r.wobben@home.nl> wrote:
Roelof Wobben schreef op 10-11-2014 20:59:
last5 :: [a] -> Maybe a
   last5 = foldr acc Nothing where
       acc x Nothing  = Just x
       acc _ j        = j

When I enter this in GHCI  I see this error :

Illegal type signature: ‘[a] -> Maybe a last5’




_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners