]> Git — Sourcephile - haskell/symantic-base.git/blob - src/Symantic/Semantics/Identity.hs
iface: add semantic `Identity`
[haskell/symantic-base.git] / src / Symantic / Semantics / Identity.hs
1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 -- | This module provides the 'Identity' semantic
3 -- which interprets the combinators as a Haskell value.
4 module Symantic.Semantics.Identity
5 ( Identity(..)
6 ) where
7
8 import Control.Applicative qualified as App
9 import Data.Either qualified as Either
10 import Data.Eq qualified as Eq
11 import Data.Function qualified as Fun
12 import Data.Functor.Identity (Identity(..))
13 import Data.Maybe qualified as Maybe
14
15 import Symantic.Syntaxes.Classes
16
17 -- * Type 'Identity'
18
19 instance Abstractable Identity where
20 lam f = Identity (runIdentity Fun.. f Fun.. Identity)
21 instance Abstractable1 Identity where
22 lam1 f = Identity (runIdentity Fun.. f Fun.. Identity)
23 instance Anythingable Identity
24 instance Constantable c Identity where
25 constant = Identity
26 instance Eitherable Identity where
27 either = Identity Either.either
28 left = Identity Either.Left
29 right = Identity Either.Right
30 instance Equalable Identity where
31 equal = Identity (Eq.==)
32 instance IfThenElseable Identity where
33 ifThenElse test ok ko = Identity
34 (if runIdentity test
35 then runIdentity ok
36 else runIdentity ko)
37 instance Instantiable Identity where
38 Identity f .@ Identity x = Identity (f x)
39 instance Listable Identity where
40 cons = Identity (:)
41 nil = Identity []
42 instance Maybeable Identity where
43 nothing = Identity Maybe.Nothing
44 just = Identity Maybe.Just
45 instance Unabstractable Identity where
46 ap = Identity (App.<*>)
47 const = Identity Fun.const
48 id = Identity Fun.id
49 (.) = Identity (Fun..)
50 flip = Identity Fun.flip
51 ($) = Identity (Fun.$)
52 instance Varable Identity where
53 var = Fun.id