add Literal from yanais

fogti
Aug 22, 2024, 3:43 PM
EFHQIYTCATMP3PQNVAUSK75EDA5E3QCOB737TTJWURPFCUO7VSXQC

Dependencies

  • [2] GMGXNJEP add back more stuff from yanais
  • [*] 6XMVEBZA add simple stuff (e.g. haskell basics)

Change contents

  • file addition: Syntax (d--r------)
    [4.750]
  • file addition: Literal.hs (----------)
    [0.18]
    {-# LANGUAGE DeriveFunctor, DeriveGeneric #-}
    module GardGround.Syntax.Literal (
    IntSz(..),
    PrimTy(..),
    Literal(..),
    lookupBinder,
    ) where
    import Data.Hashable (Hashable)
    import Generic.Data (Generic)
    import Numeric.Natural (Natural)
    -- | integer sizes
    data IntSz = PI8 | PI16 | PI32 | PI64 | PIsize
    deriving (Show, Eq, Generic)
    instance Hashable IntSz
    -- | primitive type literals
    data PrimTy = PtType | PtBool | PtString | PtIntSz | PtUnsInt IntSz | PtSigInt IntSz
    deriving (Show, Eq, Generic)
    instance Hashable PrimTy
    -- | all possible literals
    data Literal = LPrimTy PrimTy | LIntSz IntSz | LNat Natural
    deriving (Show, Eq, Generic)
    instance Hashable Literal
    -- | lookup a value in a list by its position (via Natural instead of Int);
    -- this is only here because it has no dependencies
    lookupBinder :: [a] -> Natural -> Maybe a
    lookupBinder = foldr ffun (const Nothing)
    where
    ffun x _ 0 = Just x
    ffun _ r k = r (k-1)
  • edit in core/gardground-core.cabal at line 18
    [4.5011]
    [4.5011]
    GardGround.Syntax.Literal
  • edit in core/gardground-core.cabal at line 26
    [4.5101]
    [2.10878]
    DeriveFunctor