Skip to content

Instantly share code, notes, and snippets.

@Kazark
Created September 15, 2016 19:24
Show Gist options
  • Save Kazark/5c175dcb8af9077829c0b50be3c8f794 to your computer and use it in GitHub Desktop.
Save Kazark/5c175dcb8af9077829c0b50be3c8f794 to your computer and use it in GitHub Desktop.
Code from LambdaConf 2015 Type Kwan Do workshop
{-# 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