summaryrefslogtreecommitdiff
path: root/TrieMap/Applicative.hs
blob: 5aaddc13e34487efd847c7bbcf31da8fdbd6e47a (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
module TrieMap.Applicative(Id(..), (.:), (<.>), on, build) where

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

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`