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
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
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
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
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
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
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
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?
>>