Created
September 15, 2016 19:24
-
-
Save Kazark/5c175dcb8af9077829c0b50be3c8f794 to your computer and use it in GitHub Desktop.
Code from LambdaConf 2015 Type Kwan Do workshop
This file contains hidden or 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
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module TKD where | |
import Control.Applicative | |
befunge :: (x -> y) -> (y -> (w, z)) -> x -> w | |
befunge f g = | |
fst . g . f | |
newtype Compose f g a = | |
Compose { getCompose :: f (g a) } | |
instance (Functor f, Functor g) => Functor (Compose f g) where | |
fmap :: (a -> b) -> Compose f g a -> Compose f g b | |
fmap f (Compose fga) = | |
Compose $ (fmap . fmap) f fga | |
instance (Applicative f, Applicative g) => Applicative (Compose f g) where | |
pure :: a -> Compose f g a | |
pure = Compose . pure . pure | |
(<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b | |
(<*>) (Compose fgab) (Compose fga) = | |
Compose $ (fmap (<*>) fgab) <*> fga |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment