summaryrefslogtreecommitdiff
path: root/TrieMap/Applicative.hs
blob: 74291f4de61b328ee9ca3885e4e42930eedd3f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module TrieMap.Applicative(Id(..), (.:), (<.>), on, build) where

import Control.Monad
import Control.Applicative
import Data.Traversable (sequenceA)
import GHC.Exts (build)

newtype Id a = Id {unId :: a}

instance Functor Id where
	fmap f (Id x) = Id (f x)

instance Applicative Id where
	pure = return
	(<*>) = ap

instance Monad Id where
	return = Id
	m >>= k = k (unId m)

(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(.:) = (.) . (.)

(<.>) :: Functor f => (b -> c) -> (a -> f b) -> (a -> f c)
(<.>) = (.) . (<$>)

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
(f `on` g) x y = f (g x) (g y)

infixr 9 <.>
infixr 9 .:
infixr 8 `on`