Are these soloutions all valid and a good use of Haskell

Hello, I tried to solve the first problem of the 99 haskell problems on 3 seperate ways. The problem is that I have to find the last item of a list. The solutions I found with a little help of this mailinglist are : last2::[a]-> Maybe a; last2 [] = Nothing; last2 ([x]) = Just x; last2 (_:xs) = last2 xs last3::[a]-> Maybe a; last3 x | null x = Nothing | null xs = Just (head x) | otherwise = last3 (tail x) where xs = tail x last4::[a]-> Maybe a; last4 x = case x of [] -> Nothing ; [x] -> Just x ; (_:xs) -> last4 xs main = print $ (last2 [] ) What do you experts think of the different ways ? Roelof

On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions. All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you. -Karl

I've seen this mentioned a couple of times - that you should avoid explicit recursion where possible in Haskell (although I can't find the references now). Is this to make programs easier to understand, or more compact, or is there a performance benefit? Chris -----Original Message----- From: Beginners [mailto:beginners-bounces@haskell.org] On Behalf Of Karl Voelker Sent: Monday, November 10, 2014 10:17 AM To: beginners@haskell.org Subject: Re: [Haskell-beginners] Are these soloutions all valid and a good use of Haskell On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions. All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you. -Karl _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners KCG Europe Limited is authorized and regulated by the Financial Conduct Authority. Registered Office 55 Basinghall Street, London, EC2V 5DU. Registered in England & Wales No. 03632121 This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link: http://www.kcg.com/legal/global-disclosures

Never mind - I should have Googled this: https://www.haskell.org/haskellwiki/Haskell_programming_tips#Avoid_explicit_... Chris -----Original Message----- From: Beginners [mailto:beginners-bounces@haskell.org] On Behalf Of Chris Linton-Ford Sent: Monday, November 10, 2014 10:25 AM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Are these soloutions all valid and a good use of Haskell I've seen this mentioned a couple of times - that you should avoid explicit recursion where possible in Haskell (although I can't find the references now). Is this to make programs easier to understand, or more compact, or is there a performance benefit? Chris -----Original Message----- From: Beginners [mailto:beginners-bounces@haskell.org] On Behalf Of Karl Voelker Sent: Monday, November 10, 2014 10:17 AM To: beginners@haskell.org Subject: Re: [Haskell-beginners] Are these soloutions all valid and a good use of Haskell On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions. All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you. -Karl _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners KCG Europe Limited is authorized and regulated by the Financial Conduct Authority. Registered Office 55 Basinghall Street, London, EC2V 5DU. Registered in England & Wales No. 03632121 This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link: http://www.kcg.com/legal/global-disclosures _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners KCG Europe Limited is authorized and regulated by the Financial Conduct Authority. Registered Office 55 Basinghall Street, London, EC2V 5DU. Registered in England & Wales No. 03632121 This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link: http://www.kcg.com/legal/global-disclosures

On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.
In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.
Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list). -- Frerich Raabe - raabe@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

Thanks all, I will try to make a fold solution as soon as I see that functional explained in the learnyouahaskell. Roelof Frerich Raabe schreef op 10-11-2014 11:43:
On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.
In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.
Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list).

I tried and so far I have this : last5 = foldl(\acc x -> if x=[] then x else acc xs) [] xs But now I get parse error on the -> part. Roelof Roelof Wobben schreef op 10-11-2014 13:47:
Thanks all,
I will try to make a fold solution as soon as I see that functional explained in the learnyouahaskell.
Roelof
Frerich Raabe schreef op 10-11-2014 11:43:
On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.
In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.
Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list).
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi Roelof It seems like you try to do too many things at once. Here's how you could go about this step-by-step and let GHC help you implement your functions along the way: First, give the type signature of your function: last5 :: [a] -> Maybe a last5 = undefined Now, load this into GHCi or compile with GHC. If it compiles, you're on the right track. Now, you want to implement it using a fold (try both, foldl and foldr): last5 :: [a] -> Maybe a last5 xs = foldr _ _ xs The underscores are 'type holes'. This tells the compiler to give you some information about what is supposed to be placed at the two positions. For the moment, we are only interested in the types of the things that go there. The compiler will tell you, that the hole at the first position is of type a -> Maybe a -> Maybe a and the hole at the second position is of type Maybe a Now, instead of filling the holes in place, let's define two helper functions together with their type signatures. You can later on inline them in your definition of last5, but for the time being, let's get as much help from the compiler as we can. last5 :: [a] -> Maybe a last5 xs = foldr acc initial xs acc :: a -> Maybe a -> Maybe a acc = undefined initial :: Maybe a initial = undefined Again, compile or load into GHCi. If you did anything wrong, the compiler will tell you so. There is only one possible way to implement function `initial` without cheating (= raising an error) initial :: Maybe a initial = Nothing Function `acc` can be implemented in several ways. Only one of them will lead to the desired behavior. Finding out the proper implementation is the main point of this folding-exercise. Try also an implementation using foldl. Does it behave as expected? What are the differences compared to foldr? When you feed your implementations a huge list - say [1..20000000] - what happens? Note that whenever you get an error message in a rather complex function implementation, move local function definitions and lambdas to the top level, give them a type signature and implement them separately one at a time. Use type holes to let the compiler give assistance with type signatures and possible implementations. Once everything compiles and runs as expected, move the toplevel definitions back to where you'd like them best. Stefan PS: A more succint implementation of last5 would use currying: last5 = foldr acc initial PPS: If you get a stack overflow with very large lists, try using foldl' from Data.List (or better, once you learned about the Foldable type class, from Data.Foldable). On Mon, Nov 10, 2014 at 02:28:08PM +0100, Roelof Wobben wrote:
I tried and so far I have this :
last5 = foldl(\acc x -> if x=[] then x else acc xs) [] xs
But now I get parse error on the -> part.
Roelof
Roelof Wobben schreef op 10-11-2014 13:47:
Thanks all,
I will try to make a fold solution as soon as I see that functional explained in the learnyouahaskell.
Roelof
Frerich Raabe schreef op 10-11-2014 11:43:
On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.
In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.
Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list).
_______________________________________________ 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

Just a quick note: That's 'typed holes' not 'type holes' ... On Mon, Nov 10, 2014 at 03:12:20PM +0100, Stefan Höck wrote:
Hi Roelof
It seems like you try to do too many things at once. Here's how you could go about this step-by-step and let GHC help you implement your functions along the way:
First, give the type signature of your function:
last5 :: [a] -> Maybe a last5 = undefined
Now, load this into GHCi or compile with GHC. If it compiles, you're on the right track. Now, you want to implement it using a fold (try both, foldl and foldr):
last5 :: [a] -> Maybe a last5 xs = foldr _ _ xs
The underscores are 'type holes'. This tells the compiler to give you some information about what is supposed to be placed at the two positions. For the moment, we are only interested in the types of the things that go there. The compiler will tell you, that the hole at the first position is of type
a -> Maybe a -> Maybe a
and the hole at the second position is of type
Maybe a
Now, instead of filling the holes in place, let's define two helper functions together with their type signatures. You can later on inline them in your definition of last5, but for the time being, let's get as much help from the compiler as we can.
last5 :: [a] -> Maybe a last5 xs = foldr acc initial xs
acc :: a -> Maybe a -> Maybe a acc = undefined
initial :: Maybe a initial = undefined
Again, compile or load into GHCi. If you did anything wrong, the compiler will tell you so. There is only one possible way to implement function `initial` without cheating (= raising an error)
initial :: Maybe a initial = Nothing
Function `acc` can be implemented in several ways. Only one of them will lead to the desired behavior. Finding out the proper implementation is the main point of this folding-exercise. Try also an implementation using foldl. Does it behave as expected? What are the differences compared to foldr? When you feed your implementations a huge list - say [1..20000000] - what happens?
Note that whenever you get an error message in a rather complex function implementation, move local function definitions and lambdas to the top level, give them a type signature and implement them separately one at a time. Use type holes to let the compiler give assistance with type signatures and possible implementations. Once everything compiles and runs as expected, move the toplevel definitions back to where you'd like them best.
Stefan
PS: A more succint implementation of last5 would use currying:
last5 = foldr acc initial
PPS: If you get a stack overflow with very large lists, try using foldl' from Data.List (or better, once you learned about the Foldable type class, from Data.Foldable).
On Mon, Nov 10, 2014 at 02:28:08PM +0100, Roelof Wobben wrote:
I tried and so far I have this :
last5 = foldl(\acc x -> if x=[] then x else acc xs) [] xs
But now I get parse error on the -> part.
Roelof
Roelof Wobben schreef op 10-11-2014 13:47:
Thanks all,
I will try to make a fold solution as soon as I see that functional explained in the learnyouahaskell.
Roelof
Frerich Raabe schreef op 10-11-2014 11:43:
On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
What do you experts think of the different ways ?
2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.
In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.
Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list).
_______________________________________________ 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

No problem . Im strugelling to make acc work. I try to say that if the input list has only 1 item the outcome is the head of that list. But doing acc = Just (head a) or doing acc = Just (head acc) gives both that acc or a is not in scope also doing acc x = Just (head x) gives a error messages that the types are not matching. Roelof Stefan Höck schreef op 10-11-2014 15:23:
Just a quick note: That's 'typed holes' not 'type holes' ...
On Mon, Nov 10, 2014 at 03:12:20PM +0100, Stefan Höck wrote:
Hi Roelof
It seems like you try to do too many things at once. Here's how you could go about this step-by-step and let GHC help you implement your functions along the way:
First, give the type signature of your function:
last5 :: [a] -> Maybe a last5 = undefined
Now, load this into GHCi or compile with GHC. If it compiles, you're on the right track. Now, you want to implement it using a fold (try both, foldl and foldr):
last5 :: [a] -> Maybe a last5 xs = foldr _ _ xs
The underscores are 'type holes'. This tells the compiler to give you some information about what is supposed to be placed at the two positions. For the moment, we are only interested in the types of the things that go there. The compiler will tell you, that the hole at the first position is of type
a -> Maybe a -> Maybe a
and the hole at the second position is of type
Maybe a
Now, instead of filling the holes in place, let's define two helper functions together with their type signatures. You can later on inline them in your definition of last5, but for the time being, let's get as much help from the compiler as we can.
last5 :: [a] -> Maybe a last5 xs = foldr acc initial xs
acc :: a -> Maybe a -> Maybe a acc = undefined
initial :: Maybe a initial = undefined
Again, compile or load into GHCi. If you did anything wrong, the compiler will tell you so. There is only one possible way to implement function `initial` without cheating (= raising an error)
initial :: Maybe a initial = Nothing
Function `acc` can be implemented in several ways. Only one of them will lead to the desired behavior. Finding out the proper implementation is the main point of this folding-exercise. Try also an implementation using foldl. Does it behave as expected? What are the differences compared to foldr? When you feed your implementations a huge list - say [1..20000000] - what happens?
Note that whenever you get an error message in a rather complex function implementation, move local function definitions and lambdas to the top level, give them a type signature and implement them separately one at a time. Use type holes to let the compiler give assistance with type signatures and possible implementations. Once everything compiles and runs as expected, move the toplevel definitions back to where you'd like them best.
Stefan
PS: A more succint implementation of last5 would use currying:
last5 = foldr acc initial
PPS: If you get a stack overflow with very large lists, try using foldl' from Data.List (or better, once you learned about the Foldable type class, from Data.Foldable).
On Mon, Nov 10, 2014 at 02:28:08PM +0100, Roelof Wobben wrote:
I tried and so far I have this :
last5 = foldl(\acc x -> if x=[] then x else acc xs) [] xs
But now I get parse error on the -> part.
Roelof
Roelof Wobben schreef op 10-11-2014 13:47:
Thanks all,
I will try to make a fold solution as soon as I see that functional explained in the learnyouahaskell.
Roelof
Frerich Raabe schreef op 10-11-2014 11:43:
On 2014-11-10 11:16, Karl Voelker wrote:
On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote: > What do you experts think of the different ways ? 2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions. In addition to what Karl wrote, I'd like to suggest not using the semicolon all the time -- it's not needed and just adds noise.
All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you. Right - I suggest trying to express the problem with the most abstract function first, then consider using a fold, then use manual recursion. in your particular case you could exploit that for non-empty lists, getting the last element of a list is the same as getting the first element of a reversed list (and there are ready-made functions for reversing a list and getting the first element of a list).
_______________________________________________ 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
Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi Roelof, On 10/11/14 10:10, Roelof Wobben wrote:
No problem .
Im strugelling to make acc work.
I try to say that if the input list has only 1 item the outcome is the head of that list. But doing
acc = Just (head a) or doing acc = Just (head acc) gives both that acc or a is not in scope The `a` in the type signature `acc :: a -> Maybe a -> Maybe a` is not a variable name, it is a type.
also doing acc x = Just (head x) gives a error messages that the types are not matching. :t Just (head x) Maybe a
:t acc x Maybe a -> Maybe a So, the compiler is right!
Roelof
-- Leza Morais Lutonda, Lemol-C Electronic and Telecommunication Engineer Software Development and Architecture Enthusiast http://lemol.github.io 50 Aniversario de la Cujae. Inaugurada por Fidel el 2 de diciembre de 1964 http://cujae.edu.cu

Of course the compiler is right. Im still struggeling. What I try to do is this 1) if acc is empty then a empty list so the output must be Nothing 2) if the input has only one item then it is the last so the output must be that item. 3) if the input has more then 1item then the last item is not reached so acc must have the value of the next item of the input file And I do not see how I can give acc the value of the next value of the input file maybe head xs Roelof Leza Morais Lutonda schreef op 10-11-2014 19:52:
Hi Roelof,
On 10/11/14 10:10, Roelof Wobben wrote:
No problem .
Im strugelling to make acc work.
I try to say that if the input list has only 1 item the outcome is the head of that list. But doing
acc = Just (head a) or doing acc = Just (head acc) gives both that acc or a is not in scope The `a` in the type signature `acc :: a -> Maybe a -> Maybe a` is not a variable name, it is a type.
also doing acc x = Just (head x) gives a error messages that the types are not matching. :t Just (head x) Maybe a
:t acc x Maybe a -> Maybe a
So, the compiler is right!
Roelof

Consider what happens if you apply the last function to xs.
On Monday, November 10, 2014, Roelof Wobben
Of course the compiler is right.
Im still struggeling.
What I try to do is this
1) if acc is empty then a empty list so the output must be Nothing 2) if the input has only one item then it is the last so the output must be that item. 3) if the input has more then 1item then the last item is not reached so acc must have the value of the next item of the input file
And I do not see how I can give acc the value of the next value of the input file maybe head xs
Roelof
Leza Morais Lutonda schreef op 10-11-2014 19:52:
Hi Roelof,
On 10/11/14 10:10, Roelof Wobben wrote:
No problem .
Im strugelling to make acc work.
I try to say that if the input list has only 1 item the outcome is the head of that list. But doing
acc = Just (head a) or doing acc = Just (head acc) gives both that acc or a is not in scope
The `a` in the type signature `acc :: a -> Maybe a -> Maybe a` is not a variable name, it is a type.
also doing acc x = Just (head x) gives a error messages that the types are not matching.
:t Just (head x) Maybe a
:t acc x Maybe a -> Maybe a
So, the compiler is right!
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Sent from an iPhone, please excuse brevity and typos.

Me misunderstanding actually. I'd forgotten the foldr. The answer is that
foldr calls your folding function multiple times, do you don't need to
worry about it.
On Monday, November 10, 2014, Roelof Wobben
Julian Birch schreef op 10-11-2014 20:41:
Consider what happens if you apply the last function to xs.
Then you get the last item but fold supposes to run over all items.
Or do I misunderstood the question.
Roelof
On Monday, November 10, 2014, Roelof Wobben
javascript:_e(%7B%7D,'cvml','r.wobben@home.nl');> wrote: Of course the compiler is right.
Im still struggeling.
What I try to do is this
1) if acc is empty then a empty list so the output must be Nothing 2) if the input has only one item then it is the last so the output must be that item. 3) if the input has more then 1item then the last item is not reached so acc must have the value of the next item of the input file
And I do not see how I can give acc the value of the next value of the input file maybe head xs
Roelof
Leza Morais Lutonda schreef op 10-11-2014 19:52:
Hi Roelof,
On 10/11/14 10:10, Roelof Wobben wrote:
No problem .
Im strugelling to make acc work.
I try to say that if the input list has only 1 item the outcome is the head of that list. But doing
acc = Just (head a) or doing acc = Just (head acc) gives both that acc or a is not in scope
The `a` in the type signature `acc :: a -> Maybe a -> Maybe a` is not a variable name, it is a type.
also doing acc x = Just (head x) gives a error messages that the types are not matching.
:t Just (head x) Maybe a
:t acc x Maybe a -> Maybe a
So, the compiler is right!
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Sent from an iPhone, please excuse brevity and typos.
_______________________________________________ Beginners mailing listBeginners@haskell.org javascript:_e(%7B%7D,'cvml','Beginners@haskell.org');http://www.haskell.org/mailman/listinfo/beginners
-- Sent from an iPhone, please excuse brevity and typos.
participants (7)
-
Chris Linton-Ford
-
Frerich Raabe
-
Julian Birch
-
Karl Voelker
-
Leza Morais Lutonda
-
Roelof Wobben
-
Stefan Höck