Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-16 Thread Kaoru Hosokawa
On 2005/04/16, at 12:57, Hamilton Richards wrote: At 10:50 AM +0900 2005/4/16, Kaoru Hosokawa wrote: My solution based on Bernie's solution: init :: [a] - [a] init xs = foldr (left (length xs)) xs xs left :: Int - a - [a] - [a] left n x xs | n == length xs = [] | otherwise = x : xs

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-14 Thread Hamilton Richards
At 6:53 PM +0200 2005/4/12, Henning Thielemann wrote: On Tue, 12 Apr 2005, Hamilton Richards wrote: Here's a solution: init :: [a] - [a] init xs = tail (foldr keep [] xs) where keep :: a - [a] - [a] keep x [] = [x] keep x [y] = [x,x] keep x (y:z:zs) = x:x:y:zs Nice idea!

[Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Kaoru Hosokawa
I've been working through Thompson's exercises and got to one I could not solve. It's Exercise 9.13. This is where I need to define init using foldr. init :: [a] - [a] init Greggery Peccary ~ Greggary Peccar This is as far as I got: init xs = foldr left [] xs

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Bernard Pope
On Sun, 2005-04-10 at 15:44 +0900, Kaoru Hosokawa wrote: I've been working through Thompson's exercises and got to one I could not solve. It's Exercise 9.13. This is where I need to define init using foldr. init :: [a] - [a] init Greggery Peccary ~ Greggary Peccar Hi, Here's

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Daniel Fischer
Am Sonntag, 10. April 2005 08:44 schrieb Kaoru Hosokawa: I've been working through Thompson's exercises and got to one I could not solve. It's Exercise 9.13. This is where I need to define init using foldr. init :: [a] - [a] init Greggery Peccary ~ Greggary Peccar This is as

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Daniel Fischer
On second thoughts, I think Maybe [a] is nicer than (Bool, [a]). D. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Christoph Bauer
Kaoru Hosokawa [EMAIL PROTECTED] writes: I've been working through Thompson's exercises and got to one I could not solve. It's Exercise 9.13. This is where I need to define init using foldr. init :: [a] - [a] init Greggery Peccary ~ Greggary Peccar This is as far as I got:

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Christoph Bauer
Daniel Fischer [EMAIL PROTECTED] writes: On second thoughts, I think Maybe [a] is nicer than (Bool, [a]). Cool, this was my idea, too. Best regards, Christop Bauer -- let () = let rec f a w i j = Printf.printf %.20f\r a; let a1 = a *. i /. j in if w then f a1 false (i +. 2.0) j else f a1

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Henning Thielemann
On Mon, 11 Apr 2005, Christoph Bauer wrote: Kaoru Hosokawa [EMAIL PROTECTED] writes: I've been working through Thompson's exercises and got to one I could not solve. It's Exercise 9.13. This is where I need to define init using foldr. init :: [a] - [a] init Greggery Peccary ~

Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-10 Thread Daniel Fischer
Am Montag, 11. April 2005 15:59 schrieb Christoph Bauer: Ok, my second haskell program ;-): module Init where import Maybe left :: a - Maybe [a] - Maybe [a] left x None = (Just []) Nothing, as below :-) left x (Just l) = (Just (x:l)) init :: [a] - [a] init xs =