Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Created November 24, 2020 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Heimdell/85796095a57c6b2aa9733fb24f71437e to your computer and use it in GitHub Desktop.
Save Heimdell/85796095a57c6b2aa9733fb24f71437e to your computer and use it in GitHub Desktop.
module AST where
import Data.Constraint
import Data.Functor.Compose
import Data.Fix
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.TypeLits
newtype Root carrier ph w = Root { unRoot :: Fix (Compose w (carrier ph w)) }
type AST = Root AST_
data AST_ (ph :: k) w self where
Var :: Name -> AST_ ph w self
App :: self -> [self] -> AST_ ph w self
Lam :: [w (Param ph w)] -> self -> AST_ ph w self
Let :: [w (Decl ph w self)] -> self -> AST_ ph w self
Match :: self -> [w (Alt ph w self)] -> AST_ ph w self
Const :: Constant -> AST_ ph w self
BIF :: Builtin -> AST_ ph w self
data Param ph w = Param Name (w (Type ph w))
type Type = Root Type_
data Type_ ph w self
= TConst Name
| TRigid Name
| TVar Name
| TArr self self
| TApp self self
| Forall Name self self
| U
| TypedHole
data Constant
= I Integer
| S String
data Builtin = Builtin
{ bifName :: Name
, bifArity :: Integer
}
data Decl ph w ast
= Def (w (Param ph w)) ast
| Data (w (Param ph w)) [w (Ctor ph w)]
data Ctor ph w = Ctor Name [w (Param ph w)] (w (Type ph w))
data Alt ph w ast
= Alt (w (Pattern ast ph w)) ast
type Pattern ast = Root (Pattern_ ast)
data Pattern_ ast ph w self
= IsHole Name
| IsView ast self
| IsCtor Name [self]
| IsConst Constant
| IsWildcard
newtype Name = Name Text
name: adadsa
version: 1.0.0
dependencies:
- base
- constraints
- data-fix
- free
- exceptions
- mtl
- text
default-extensions:
- GADTs
- BlockArguments
- DataKinds
- RankNTypes
- TypeOperators
- MultiParamTypeClasses
- AllowAmbiguousTypes
- TypeFamilies
- UndecidableInstances
- ConstraintKinds
- FlexibleContexts
- TypeApplications
- ScopedTypeVariables
- FlexibleInstances
- DefaultSignatures
- QuantifiedConstraints
- LambdaCase
- DerivingStrategies
- DeriveAnyClass
- StandaloneDeriving
- PolyKinds
library:
source-dirs:
- .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment