Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hdgarrood
Created May 10, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdgarrood/41f1ddea5b5792b4af035e36aa5ee2ce to your computer and use it in GitHub Desktop.
Save hdgarrood/41f1ddea5b5792b4af035e36aa5ee2ce to your computer and use it in GitHub Desktop.
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