[ create a new paste ] login | about

Link: http://codepad.org/cbkfjidB    [ raw code | fork ]

Haskell, pasted on Feb 7:
{-# LANGUAGE                                                                                         
 GADTs,                                                                                              
 FlexibleInstances,                                                                                  
 UndecidableInstances,                                                                               
 MultiParamTypeClasses,                                                                              
 FunctionalDependencies,                                                                             
 TypeOperators                                                                                       
 #-}

module Stuff where

infixr 5 :+

data Nil
data a :+ r

data List a where
  Nil :: List Nil
  (:+) :: a -> List c -> List (a :+c)

class Append a b c | a b -> c where
  append :: List a -> List b -> List c

instance Append Nil a a where
  append Nil v = v

instance (Append l1 l2 r) => Append (f :+ l1) l2 (f :+ r) where
  append (f :+ l1) l2 = f :+ (append l1 l2)


class Foldr f b a c | f -> b c, a -> f where
  foldrList :: List f -> b -> List a -> c
instance Foldr a v Nil v where
  foldrList _ v _ = v
instance (Foldr r1 b r2 r) => Foldr ((a -> r -> c) :+ r1) b (a :+ r2) c where
  foldrList (f :+ r1) b (a :+ r2) = f a (foldrList r1 b r2)


Create a new paste based on this one


Comments: