Last active
August 4, 2016 01:05
-
-
Save mpickering/99d62ccdb73f49840220 to your computer and use it in GitHub Desktop.
Native idiom brackets
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
-- https://wiki.haskell.org/Idiom_brackets | |
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleContexts, FlexibleInstances, UndecidableInstances #-} | |
import Control.Applicative | |
import Control.Monad.Identity | |
class Applicative i => Idiomatic i f g | g -> f i where | |
idiomatic :: i f -> g | |
iI :: Idiomatic i f g => f -> g | |
iI = idiomatic . pure | |
data Ii = Ii | |
instance Applicative i => Idiomatic i x (Ii -> i x) where | |
idiomatic xi Ii = xi | |
instance Idiomatic i f g => Idiomatic i (s -> f) (i s -> g) where | |
idiomatic sfi si = idiomatic (sfi <*> si) | |
f :: Identity Int | |
f = iI (+) (Identity 5) (Identity 6) Ii |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow...