Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE NoImplicitPrelude #-}
- import List
- import Functor --for test
- class (Functor f) => Applicative f where
- pure :: a -> f a
- (<*>) :: f (a -> b) -> f a -> f b
- --Test. Works for me.
- instance Applicative List where
- pure x = (Cons x Nil)
- (Cons f Nil) <*> (Cons x Nil) = (Cons (f x) Nil)
- (Cons f l) <*> (Cons x Nil) = (Cons (f x) (l <*> x))
- (Cons f Nil) <*> (Cons x l) = (Cons (f x) (f <*> l))
- (Cons f l1) <*> (Cons x l2) = (Cons (f x) (Cons (l1 <*> x) (Cons (f <*> l2) (l1 <*> l2))))
Add Comment
Please, Sign In to add comment