Skip to content

Instantly share code, notes, and snippets.

@hdgarrood hdgarrood/Main.purs

Created May 10, 2016
Embed
What would you like to do?
module Main where
import Prelude
import Data.Either
import Data.Functor.Compose
import Control.Monad.Eff.Console (print)
class Convert a b where
convert :: a -> b
data A = A Int Int
type B = Array Int
instance convertId :: Convert a a where
convert = id
instance convertA :: Convert (Array Int) A where
convert [x,y] = A x y
instance convertChain :: (Convert b a, Convert r r') => Convert (a -> r) (b -> r') where
convert a2r b = convert (a2r (convert b))
f :: A -> A -> Int
f (A a b) (A c d) = a + b + c + d
g :: B -> B -> Int
g = convert f
f' :: A -> A -> A -> A -> Int
f' a b c d = f a b + f c d
g' :: B -> B -> B -> B -> Int
g' = convert f'
main = print (g' [1,2] [3,4] [5,6] [7,8])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.