Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-11 Thread Andrew Coppin
Andrew Coppin wrote: OK, so I sat down today and tried this, but I can't figure out how. There are various examples of type-level arithmetic around the place. For example, http://www.haskell.org/haskellwiki/Type_arithmetic (This is THE first hit on Google, by the way. Haskell is apparently

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-11 Thread Ryan Ingram
Actually, at least in GHC, associated types are just syntax sugar for type families. That is, this code: class Container c where type Element c :: * view :: c -> Maybe (Element c,c) instance Container [a] where type Element [a] = a view [] = Nothing view (x:xs) = Just (x,xs) is t

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-11 Thread Robert Greayer
What Ryan said, and here's an example of addition with ATs, specifically (not thoroughly tested, but tested a little). The translation to TFs sans ATs is straightforward. class Add a b where type SumType a b instance Add Zero Zero where type SumType Zero Zero = Zero instance Add (Succ a

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-12 Thread Andrew Coppin
Ryan Ingram wrote: Actually, at least in GHC, associated types are just syntax sugar for type families. That is, this code: class Container c where type Element c :: * view :: c -> Maybe (Element c,c) instance Container [a] where type Element [a] = a view [] = Nothing view (x:xs

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-12 Thread Andrew Coppin
Robert Greayer wrote: What Ryan said, and here's an example of addition with ATs, specifically (not thoroughly tested, but tested a little). The translation to TFs sans ATs is straightforward. class Add a b where type SumType a b instance Add Zero Zero where type SumType Zero Zero = Ze

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-12 Thread Robert Greayer
On Fri, Feb 12, 2010 at 2:11 PM, Andrew Coppin wrote: > OK, well in that case, I'm utterly puzzled as to why both forms exist in the > first place. If TFs don't allow you to do anything that can't be done with > ATs, why have them? > > My head hurts... > I think the question is the reverse -- why

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-12 Thread Edward Kmett
On Fri, Feb 12, 2010 at 2:11 PM, Andrew Coppin wrote: > OK, well in that case, I'm utterly puzzled as to why both forms exist in > the first place. If TFs don't allow you to do anything that can't be done > with ATs, why have them? > > My head hurts... You can say anything you might say with typ

Re: [Haskell-cafe] Type arithmetic with ATs/TFs

2010-02-12 Thread Luke Palmer
On Fri, Feb 12, 2010 at 2:10 PM, Edward Kmett wrote: > On Fri, Feb 12, 2010 at 2:11 PM, Andrew Coppin > wrote: >> >> OK, well in that case, I'm utterly puzzled as to why both forms exist in >> the first place. If TFs don't allow you to do anything that can't be done >> with ATs, why have them? >>