{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | This module provides the 'Identity' semantic
-- which interprets the combinators as a Haskell value.
module Symantic.Semantics.Identity
  ( Identity(..)
  ) where

import Control.Applicative qualified as App
import Data.Either qualified as Either
import Data.Eq qualified as Eq
import Data.Function qualified as Fun
import Data.Functor.Identity (Identity(..))
import Data.Maybe qualified as Maybe

import Symantic.Syntaxes.Classes

-- * Type 'Identity'

instance Abstractable Identity where
  lam f = Identity (runIdentity Fun.. f Fun.. Identity)
instance Abstractable1 Identity where
  lam1 f = Identity (runIdentity Fun.. f Fun.. Identity)
instance Anythingable Identity
instance Constantable c Identity where
  constant = Identity
instance Eitherable Identity where
  either = Identity Either.either
  left = Identity Either.Left
  right = Identity Either.Right
instance Equalable Identity where
  equal = Identity (Eq.==)
instance IfThenElseable Identity where
  ifThenElse test ok ko = Identity
    (if runIdentity test
    then runIdentity ok
    else runIdentity ko)
instance Instantiable Identity where
  Identity f .@ Identity x = Identity (f x)
instance Listable Identity where
  cons = Identity (:)
  nil = Identity []
instance Maybeable Identity where
  nothing = Identity Maybe.Nothing
  just = Identity Maybe.Just
instance Unabstractable Identity where
  ap = Identity (App.<*>)
  const = Identity Fun.const
  id = Identity Fun.id
  (.) = Identity (Fun..)
  flip = Identity Fun.flip
  ($) = Identity (Fun.$)
instance Varable Identity where
  var = Fun.id