Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Max Rabkin
On Sat, Feb 20, 2010 at 9:10 PM, Andrew Coppin wrote: > PS. Epic, epic comment spam. Yeah, sorry. Every now and again I decide I should deal with it. Then I rediscover that it takes about four clicks to delete each comment. Basically, I leave my blog alone until I have something (hopefully) inter

Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Andrew Coppin
Stephen Tetley wrote: Hi Andrew "Spot the difference" data Property x y = forall s. Property s (x -> s -> s) (s -> y) data Fold b c = forall a. F (a -> b -> a) a (a -> c) The later is from: http://squing.blogspot.com/2008/11/beautiful-folding.html Max Rabkin's is is closer to the original ar

Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Stephen Tetley
Hi Andrew "Spot the difference" data Property x y = forall s. Property s (x -> s -> s) (s -> y) data Fold b c = forall a. F (a -> b -> a) a (a -> c) The later is from: http://squing.blogspot.com/2008/11/beautiful-folding.html Max Rabkin's is is closer to the original argument ordering of foldl

Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Andrew Coppin
Anyway, for yours: try to implement (.) :: Property b c -> Property a b -> Property a c, and first :: Property a b -> Property (a,c) (b,c). Then you will have an arrow. (.) = flip (>==>) first p = p >==< pure id No, not quite. \p -> p >==< pure id :: Property a b -> Property a (b, a) W

Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Andrew Coppin
Luke Palmer wrote: On Sat, Feb 20, 2010 at 3:30 AM, Andrew Coppin wrote: Have I just invented arrows? No... you have a data type which is *an* Arrow (probably/almost). Well, OK, that's kind of what I meant. ;-) The pure implementation bugs me because of its use of undefined. Migh

Re: [Haskell-cafe] Computing sums

2010-02-20 Thread Luke Palmer
On Sat, Feb 20, 2010 at 3:30 AM, Andrew Coppin wrote: > Have I just invented arrows? No... you have a data type which is *an* Arrow (probably/almost). The pure implementation bugs me because of its use of undefined. Might still be okay though. I would be more comfortable if it could not output

[Haskell-cafe] Computing sums

2010-02-20 Thread Andrew Coppin
The other day, I found myself writing the following code: data Property x y = forall s. Property s (x -> s -> s) (s -> y) step :: x -> Property x y -> Property x y step x (Property s f g) = Property (f x s) f g read :: Property x y -> y read (Property s _ g) = g s pure :: (x -> y) -> Property