Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ring a where
- (+) :: a -> a -> a
- (*) :: a -> a -> a
- zero :: a
- one :: a
- (-) :: a -> a -> a
- fromInteger :: Integer -> a
- newtype Poly x = Poly { eval :: Ring r => (x -> r) -> r } deriving Functor
- instance Ring (Poly x) where
- Poly p + Poly q = Poly (\x -> p x + q x)
- Poly p * Poly q = Poly (\x -> p x * q x)
- zero = Poly (const zero)
- one = Poly (const one)
- Poly p - Poly q = Poly (\x -> p x - q x)
- fromInteger n = Poly (const $ fromInteger n)
- instance Applicative Poly where
- pure x = Poly (\xs -> xs x)
- (<*>) = ap
- instance Monad Poly where
- Poly p >>= f = p f
- @ :: Poly () -> Poly a -> Poly a
- @ p q = p >>= const q
- poly :: (forall r . Ring r => (x -> r) -> r) -> Poly x
- poly = Poly
- poly1 :: (forall r . Ring r => r -> r) -> Poly ()
- poly1 f = poly (\x -> f (x ()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement