[Haskell-cafe] Re: defining last using foldr

2007-08-16 Thread Jon Fairbairn
Chaddaï Fouché [EMAIL PROTECTED] writes: so you need an f so that c `f` x is c (for any c and x) and yet (b `f` c) is c for any c and b -- this is impossible (or I'm asleep). Well, it isn't impossible but quite hard (and not even standard H98 if I'm not mistaken) If it is possible, I'm

Re: [Haskell-cafe] Re: defining last using foldr

2007-08-16 Thread Chaddaï Fouché
16 Aug 2007 10:11:24 +0100, Jon Fairbairn [EMAIL PROTECTED]: snip my quote I certainly wouldn't count such a thing as a valid solution. It's always amazed me that C uses as standard a mechanism of ending strings that is so obviously an error-prone hack. I'm completely with you on that !

[Haskell-cafe] Re: defining last using foldr

2007-08-16 Thread Al Falloon
Kurt Hutchinson wrote: On 8/15/07, Alexteslin [EMAIL PROTECTED] wrote: I am really sorry, but i still can't define the function. The chapter the exercise is in precedes algebraic types or Maybe a types. And is seems that must being easy to define. I answered some exercises on using foldr such

Re: [Haskell-cafe] Re: defining last using foldr

2007-08-15 Thread Chaddaï Fouché
2007/8/15, Aaron Denney [EMAIL PROTECTED]: The original last fail on empty list, it's far easier to obtain the same semantic with foldl than with foldr, in fact it isn't hard at all to make it polymorphic without hassle (contrary to the foldr case) _if_ you remember that there _is_ a

[Haskell-cafe] Re: defining last using foldr

2007-08-15 Thread Aaron Denney
On 2007-08-15, Chaddaï Fouché [EMAIL PROTECTED] wrote: Still I don't see why foldl would make it harder to use Maybe than foldr (in fact it's easier). You're right. I just wasn't looking at it quite properly. -- Aaron Denney -- ___ Haskell-Cafe

[Haskell-cafe] Re: defining last using foldr

2007-08-15 Thread Jon Fairbairn
Alexteslin [EMAIL PROTECTED] writes: I am really sorry, but i still can't define the function. The chapter the exercise is in precedes algebraic types or Maybe a types. And is seems that must being easy to define. I answered some exercises on using foldr such as summing for example, but

[Haskell-cafe] Re: defining last using foldr

2007-08-14 Thread Aaron Denney
On 2007-08-14, Alexteslin [EMAIL PROTECTED] wrote: Hi, I am trying to do the exercise which asks to define built-in functions 'last' and 'init' using 'foldr' function, such as last Greggery Peccary = 'y' the type for my function is: myLast :: [Char] - Char I am not generalizing type

[Haskell-cafe] Re: defining last using foldr

2007-08-14 Thread Aaron Denney
(Quoting reformatted. Try to have your responses below what you are responding to. It makes it easier to read as a conversation.) On 2007-08-14, Alexteslin [EMAIL PROTECTED] wrote: Aaron Denney wrote: Folds replace the cons operator (:) with the function you pass it. If you want the tail of

[Haskell-cafe] Re: defining last using foldr

2007-08-14 Thread Aaron Denney
On 2007-08-14, Chaddaï Fouché [EMAIL PROTECTED] wrote: 2007/8/14, Alexteslin [EMAIL PROTECTED]: Well, i have tried cons (:) operator but when it passed to foldr doesn't work because cons operator operates first character and then the list but the foldr argument takes a function (a-a-a). Maybe

Re: [Haskell-cafe] Re: defining last using foldr

2007-08-14 Thread Chaddaï Fouché
2007/8/14, Aaron Denney [EMAIL PROTECTED]: The problem with foldl is that you can't easily make it polymorphic because of how the null case is handled. foldl1 and foldr1 are trivial, true. The original last fail on empty list, it's far easier to obtain the same semantic with foldl than with

[Haskell-cafe] Re: defining last using foldr

2007-08-14 Thread Aaron Denney
On 2007-08-14, Chaddaï Fouché [EMAIL PROTECTED] wrote: 2007/8/14, Aaron Denney [EMAIL PROTECTED]: The problem with foldl is that you can't easily make it polymorphic because of how the null case is handled. foldl1 and foldr1 are trivial, true. The original last fail on empty list, it's far