[Haskell-beginners] why is this type wrong

Alexey Shmalko rasen.dubi at gmail.com
Tue May 12 06:37:08 UTC 2015


It's because first branch of last' returns a list instead of element.

last' [] = []

The actual type is

last' :: [a] -> [a]

On Tue, May 12, 2015 at 9:33 AM Roelof Wobben <r.wobben at home.nl> wrote:

>  Hello,
>
> To practice recursion I try to make some functions of Data list myself on
> the recursive way.
>
> First I will try last.
>
> So I did this :
>
> -- | Main entry point to the application.
> module Main where
>
> -- | The main entry point.
> last' :: [a] -> a
> last' [] = []
> last' (x:xs) = last xs
>
>
> but now I see this error message :
>
> src/Main.hs at 6:12-6:14
> Couldn't match expected type
> a
>  with actual type
> [t0]
>  a
>  is a rigid type variable bound by the type signature for last' :: [a] ->
> a at
> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10
> Relevant bindings include last' :: [a] -> a (bound at
> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1)
>>
> I my oponion I have said that the input is a array and the output a
> string,
>
> Roelof
>
>
>
>
> ------------------------------
>   [image: Avast logo] <http://www.avast.com/>
>
> Dit e-mailbericht is gecontroleerd op virussen met Avast
> antivirussoftware.
> www.avast.com
>
>  _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150512/79289757/attachment.html>


More information about the Beginners mailing list