Skip to content

Instantly share code, notes, and snippets.

@mpickering
Last active August 4, 2016 01:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpickering/99d62ccdb73f49840220 to your computer and use it in GitHub Desktop.
Save mpickering/99d62ccdb73f49840220 to your computer and use it in GitHub Desktop.
Native idiom brackets
-- 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
@3noch
Copy link

3noch commented Apr 14, 2015

Wow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment