[Haskell-cafe] snd and tuples of various sizes...

Andreas Farre d00farre at dtek.chalmers.se
Fri Feb 2 07:45:04 EST 2007


Mattias Bengtsson wrote:
> On Thu, 2007-02-01 at 21:01 -1000, Tim Newsham wrote:
>> instance Second [a] a where
>>      snd [] = error "don't got none"
>>      snd (x:y:xs) = y
>
> Would'nt that instance mean this:
>   snd [] produces error
>   snd [x] gives []
>
>
> I'd implement it something like this (if this works?):
>
> instance Second [a] (Maybe a) where
>      snd [] = Nothing
>      snd [x] = Nothing
>      snd (x:y:xs) = Just y

And while we're re-implementing the Prelude with MPTC:

class Currying a b | a -> b where
 curryC   :: a -> b
 uncurryC :: b -> a

instance Currying ((a, b) -> c) (a -> b -> c) where
 curryC = curry
 uncurryC = uncurry

instance Currying ((a, b, c) -> d) (a -> b -> c -> d) where
 curryC f a b c = f (a, b, c)
 uncurryC f (a, b, c) = f a b c

instance Currying ((a, b, c, d) -> e) (a -> b -> c -> d -> e) where
 curryC f a b c d = f (a, b, c, d)
 uncurryC f (a, b, c, d) = f a b c d

instance Currying ((a, b, c, d, e) -> f) (a -> b -> c -> d -> e -> f) where
 curryC f a b c d e = f (a, b, c, d, e)
 uncurryC f (a, b, c, d, e) = f a b c d e

...

Andreas

-- 
some cannot be created more equal than others



More information about the Haskell-Cafe mailing list