{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Language.Drasil.Literal.Lang where
import Language.Drasil.Space (Space (..))
import Language.Drasil.WellTyped
data Literal where
Int :: Integer -> Literal
Str :: String -> Literal
Dbl :: Double -> Literal
ExactDbl :: Integer -> Literal
Perc :: Integer -> Integer -> Literal
deriving Literal -> Literal -> Bool
(Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool) -> Eq Literal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Literal -> Literal -> Bool
== :: Literal -> Literal -> Bool
$c/= :: Literal -> Literal -> Bool
/= :: Literal -> Literal -> Bool
Eq
instance Typed Literal Space where
infer :: TypingContext Space -> Literal -> Either Space TypeError
infer :: TypingContext Space -> Literal -> Either Space String
infer TypingContext Space
_ (Int Integer
_) = Space -> Either Space String
forall a b. a -> Either a b
Left Space
Integer
infer TypingContext Space
_ (Str String
_) = Space -> Either Space String
forall a b. a -> Either a b
Left Space
String
infer TypingContext Space
_ (Dbl Double
_) = Space -> Either Space String
forall a b. a -> Either a b
Left Space
Real
infer TypingContext Space
_ (ExactDbl Integer
_) = Space -> Either Space String
forall a b. a -> Either a b
Left Space
Real
infer TypingContext Space
_ (Perc Integer
_ Integer
_) = Space -> Either Space String
forall a b. a -> Either a b
Left Space
Real
check :: TypingContext Space -> Literal -> Space -> Either Space TypeError
check :: TypingContext Space -> Literal -> Space -> Either Space String
check = TypingContext Space -> Literal -> Space -> Either Space String
forall e t.
Typed e t =>
TypingContext t -> e -> t -> Either t String
typeCheckByInfer