[Haskell-cafe] Re: Optimization problem

2006-09-14 Thread Bertram Felgenhauer
I wrote: [1] Balancing can be done with the information in the blueprint, and mapping back is easily done by doing the transformation on the tree in reverse. I should add that this possibility was the main reason for dealing with blueprints at all. As Ross Paterson's solution shows, it's possib

[Haskell-cafe] Re: Optimization problem

2006-09-14 Thread apfelmus
Bertram Felgenhauer wrote: >> splitSeq' :: Ord a => Map a () -> [(a,b)] -> ([(a,[b])], Map a [b]) >> splitSeq' bp [] = ([], map (const []) bp) >> splitSeq' bp ((a,b):xs) = case lookup a bp bp of >> Just _ -> let (l, m) = splitSeq' bp xs in (l, update a (b:) bp m) >> _ -> let (

[Haskell-cafe] Re: Optimization problem

2006-09-15 Thread apfelmus
Ross Paterson wrote: > On Thu, Sep 14, 2006 at 05:22:05PM +0200, Bertram Felgenhauer wrote: >> [much subtle code] >> We can now build the splitStream function, using the following helper >> function: >> >>> splitSeq' :: Ord a => Map a () -> [(a,b)] -> ([(a,[b])], Map a [b]) > > This works for infi

[Haskell-cafe] Re: Optimization problem

2006-09-15 Thread apfelmus
[EMAIL PROTECTED] wrote: > type BiMap a b = (Map.Map a b, Map.Map b a) Actually BiMap is not needed at all, it suffices to have > splitStreams :: Ord a => [(a,b)] -> [(a,[b])] > splitStreams xs = > takeWhile (not . null . snd) $ toList $ splitStreams' Map.empty xs > > splitStreams' :: Ord a =

[Haskell-cafe] Re: Optimization problem

2006-09-17 Thread apfelmus
Ross Paterson wrote: > How embarrassing. Still, your code is quite subtle. As penance, here's > my explanation, separating the main idea from the knot-tying. > > The ingredients are a map type with an insertion function > [...] > insert :: Ord k => k -> a -> Map k a -> Map k a > > with a

[Haskell-cafe] Re: Optimization problem

2006-09-19 Thread apfelmus
Ross Paterson wrote: > On Sun, Sep 17, 2006 at 01:08:04PM +0200, [EMAIL PROTECTED] wrote: >> Ross Paterson wrote: >>> It's interesting that these composed transformations don't seem to cost >>> too much. >> That the composed transformations are indeed cheap is not necessarily >> disturbing. > > I

[Haskell-cafe] Re: Optimization problem

2006-09-19 Thread apfelmus
Conor McBride wrote: > Just imagine > >> data Eq a b where Refl :: Eq a a > >> coerce :: Eq a b -> a -> b Robert Dockins wrote: >>> coerce ~Refl x = x > > coerce undefined True :: String > > Bang you're dead. Or rather... Twiddle you're dead. Mom, he's scaring me! ;) Who says this functio

Re: [Haskell-cafe] Re: Optimization problem

2006-09-14 Thread Magnus Jonsson
Thanks Bertran for your solution. I have difficulty understanding it so I can't comment on it right now but I'll try to have a look at it. Do you know of any article that explains this technique, starting from very simple examples? /Magnus On Thu, 14 Sep 2006, Bertram Felgenhauer wrote: I w

Re: [Haskell-cafe] Re: Optimization problem

2006-09-14 Thread Bertram Felgenhauer
Magnus Jonsson wrote: > Thanks Bertran for your solution. I have difficulty understanding it so I > can't comment on it right now but I'll try to have a look at it. Do you > know of any article that explains this technique, starting from very > simple examples? Not really. It's a result of thin

Re: [Haskell-cafe] Re: Optimization problem

2006-09-15 Thread Henning Thielemann
On Thu, 14 Sep 2006, Bertram Felgenhauer wrote: > Magnus Jonsson wrote: > > Thanks Bertran for your solution. I have difficulty understanding it so I > > can't comment on it right now but I'll try to have a look at it. Do you > > know of any article that explains this technique, starting from v

Re: [Haskell-cafe] Re: Optimization problem

2006-09-17 Thread Ross Paterson
On Thu, Sep 14, 2006 at 07:51:59PM +0200, Bertram Felgenhauer wrote: > It's a result of thinking about lazy evaluation, and > especially lazy patterns (and let bindings) for some time. A wiki article > that helped me a lot to understand these is > > http://www.haskell.org/hawiki/TyingTheKnot >

Re: [Haskell-cafe] Re: Optimization problem

2006-09-17 Thread Donald Bruce Stewart
ross: > On Thu, Sep 14, 2006 at 07:51:59PM +0200, Bertram Felgenhauer wrote: > > It's a result of thinking about lazy evaluation, and > > especially lazy patterns (and let bindings) for some time. A wiki article > > that helped me a lot to understand these is > > > > http://www.haskell.org/hawik

Re: [Haskell-cafe] Re: Optimization problem

2006-09-18 Thread Ross Paterson
On Sun, Sep 17, 2006 at 01:08:04PM +0200, [EMAIL PROTECTED] wrote: > Ross Paterson wrote: > > It's interesting that these composed transformations don't seem to cost > > too much. > > That the composed transformations are indeed cheap is not necessarily > disturbing. I meant the composition of th

Re: [Haskell-cafe] Re: Optimization problem

2006-09-18 Thread Ross Paterson
On Mon, Sep 18, 2006 at 12:23:11AM +0100, Ross Paterson wrote: > To prove that (even for partial and infinite lists ps) > > splitSeq ps = [(a, seconds a ps) | a <- nub ps] > > [...] we can establish, by induction on the input list, > > (1) fst (splitSeq' s ps) = > [(a, seco

Re: [Haskell-cafe] Re: Optimization problem

2006-09-19 Thread Ross Paterson
On Tue, Sep 19, 2006 at 01:41:51PM +0200, [EMAIL PROTECTED] wrote: > Btw, why are there no irrefutable patterns for GADTs? Not GADTs, but existential types (whether done with GADTs or not). They can't be analysed with irrefutable patterns, of which let bindings are a special case: http://www.hask

Re: [Haskell-cafe] Re: Optimization problem

2006-09-19 Thread Conor McBride
Hi folks [EMAIL PROTECTED] wrote: Btw, why are there no irrefutable patterns for GADTs? I mean, such a sin should be shame for a non-strict language... Just imagine > data Eq a b where Refl :: Eq a a > coerce :: Eq a b -> a -> b > coerce ~Refl a = b coerce undefined True :: String Bang

Re: [Haskell-cafe] Re: Optimization problem

2006-09-19 Thread Robert Dockins
On Sep 19, 2006, at 8:52 AM, Conor McBride wrote: Hi folks [EMAIL PROTECTED] wrote: Btw, why are there no irrefutable patterns for GADTs? I mean, such a sin should be shame for a non-strict language... Just imagine > data Eq a b where Refl :: Eq a a > coerce :: Eq a b -> a -> b > coer

Re: [Haskell-cafe] Re: Optimization problem

2006-09-19 Thread Conor McBride
Robert Dockins wrote: On Sep 19, 2006, at 8:52 AM, Conor McBride wrote: Hi folks [EMAIL PROTECTED] wrote: Btw, why are there no irrefutable patterns for GADTs? I mean, such a sin should be shame for a non-strict language... Just imagine > data Eq a b where Refl :: Eq a a > coerce :: E

Re: [Haskell-cafe] Re: Optimization problem

2006-09-20 Thread Ross Paterson
On Tue, Sep 19, 2006 at 08:06:07PM +0200, [EMAIL PROTECTED] wrote: > For our optimization problem, it's only a matter of constructors on the > right hand side. They should pop out before do not look on any > arguments, so it's safe to cry "so you just know, i'm a Just". It seems the appropriate en

Re: [Haskell-cafe] Re: Optimization problem

2006-09-28 Thread Ross Paterson
On Tue, Sep 19, 2006 at 01:52:02PM +0100, Conor McBride wrote: > [EMAIL PROTECTED] wrote: > >Btw, why are there no irrefutable patterns for GADTs? > > Just imagine > > > data Eq a b where Refl :: Eq a a > > > coerce :: Eq a b -> a -> b > > coerce ~Refl a = a > > coerce undefined True :: String

RE: [Haskell-cafe] Re: Optimization problem

2006-09-28 Thread Simon Peyton-Jones
| Does anything go wrong with irrefutable patterns for existential types? Try giving the translation into System F. Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Re: Optimization problem

2006-09-28 Thread Ross Paterson
On Thu, Sep 28, 2006 at 03:22:25PM +0100, Simon Peyton-Jones wrote: > | Does anything go wrong with irrefutable patterns for existential > types? > > Try giving the translation into System F. Hmm, that's not quite as satisfying as Conor's answer for GADTs. ___