Created
May 10, 2016 16:37
-
-
Save hdgarrood/41f1ddea5b5792b4af035e36aa5ee2ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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