why is this type wrong

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
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@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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On May 12, 2015 1:32 AM, "Roelof Wobben"
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@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, Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list. You need to return a string.

last' [] = error "last' on empty list"
Otherwise, you should wrap the result in Maybe to make your function work
as safeLast.
Oh... GHC's exception seems to say you haven't defined `main` in your
module.
On Tue, May 12, 2015 at 9:42 AM Roelof Wobben
Mike Meyer schreef op 12-5-2015 om 8:39:
On May 12, 2015 1:32 AM, "Roelof Wobben"
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@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,
Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list.
You need to return a string.
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Thanks,
I did change it to this :
-- | Main entry point to the application. module Main where
-- | The main entry point. last' :: [a] -> a last' [x] = x last' (x:xs) = last xs
So I have to look at another way to say if there is a empty list then there is no answer. And when I run it i see this error message :
GHC threw an exception : Not in scope: ‘Main.main’
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Make a dummy main function,
main = return ()
And load this file in ghci to use you definition of last. The other option
is to not make this module the Main module.
Then also, you can load it in ghci.
On 12 May 2015 at 12:18, Roelof Wobben
Thanks
Can I just say Main = I will google to look how to make a safeLast.
Roelof
Alexey Shmalko schreef op 12-5-2015 om 8:46:
last' [] = error "last' on empty list"
Otherwise, you should wrap the result in Maybe to make your function work as safeLast.
Oh... GHC's exception seems to say you haven't defined `main` in your module.
On Tue, May 12, 2015 at 9:42 AM Roelof Wobben
wrote: Mike Meyer schreef op 12-5-2015 om 8:39:
On May 12, 2015 1:32 AM, "Roelof Wobben"
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@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,
Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list.
You need to return a string.
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Thanks,
I did change it to this :
-- | Main entry point to the application. module Main where
-- | The main entry point. last' :: [a] -> a last' [x] = x last' (x:xs) = last xs
So I have to look at another way to say if there is a empty list then there is no answer. And when I run it i see this error message :
GHC threw an exception : Not in scope: ‘Main.main’
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------ [image: Avast logo] http://www.avast.com/
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. www.avast.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat

I believe, you don't need main at all. Just load your source with ghci and
call your functions from there.
On Tue, May 12, 2015 at 9:48 AM Roelof Wobben
Thanks
Can I just say Main = I will google to look how to make a safeLast.
Roelof
Alexey Shmalko schreef op 12-5-2015 om 8:46:
last' [] = error "last' on empty list"
Otherwise, you should wrap the result in Maybe to make your function work as safeLast.
Oh... GHC's exception seems to say you haven't defined `main` in your module.
On Tue, May 12, 2015 at 9:42 AM Roelof Wobben
wrote: Mike Meyer schreef op 12-5-2015 om 8:39:
On May 12, 2015 1:32 AM, "Roelof Wobben"
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@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,
Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list.
You need to return a string.
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Thanks,
I did change it to this :
-- | Main entry point to the application. module Main where
-- | The main entry point. last' :: [a] -> a last' [x] = x last' (x:xs) = last xs
So I have to look at another way to say if there is a empty list then there is no answer. And when I run it i see this error message :
GHC threw an exception : Not in scope: ‘Main.main’
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------ [image: Avast logo] http://www.avast.com/
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. www.avast.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

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, 11:40 AM, at 11:40 AM, Kim-Ee Yeoh
On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben
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

The type of (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
Means that "last' [1,2,3]" should be a function, which it isn't
You can instead try,
main = (print . last') [1,2,3]
Or equivalently,
main = print . last' $ [1,2,3]
On 12 May 2015 at 18:06, Roelof Wobben
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 http://GHC.Types.IO a0’ with actual type ‘a1 -> GHC.Types.IO http://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
wrote: On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben
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 listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------ [image: Avast logo] http://www.avast.com/
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. www.avast.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat

I recommending first trying out the `last' function in ghci.
Prelude> last []
*** Exception: Prelude.last: empty list
Prelude> last [1,2]
2
Instead of using
last [] = []
You can use
last [] = error "Empty list"
Where error is defined in a way such that it can take on any type.
In ghci
Prelude> :type error
error :: [Char] -> a
On 12 May 2015 at 12:09, Mike Meyer
On May 12, 2015 1:32 AM, "Roelof Wobben"
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@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,
Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list.
You need to return a string.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat
participants (6)
-
Alexey Shmalko
-
Kim-Ee Yeoh
-
Mike Meyer
-
Nicolas SCHOEMAEKER
-
Roelof Wobben
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)