diff --git a/package.yaml b/package.yaml index 06795ba..21401e8 100644 --- a/package.yaml +++ b/package.yaml @@ -19,14 +19,20 @@ extra-source-files: description: Please see the README on GitHub at default-extensions: - - Safe + - ImportQualifiedPost - NoImplicitPrelude + - StandaloneKindSignatures + - RoleAnnotations dependencies: -- base >= 4.7 && < 5 + - base + - containers + - text + - vector ghc-options: - -Weverything +- -Wno-unsafe library: source-dirs: src diff --git a/scalie.cabal b/scalie.cabal index 18491fb..0aa5f28 100644 --- a/scalie.cabal +++ b/scalie.cabal @@ -19,17 +19,30 @@ extra-source-files: library exposed-modules: + Control.Ord.LexicographicallySorted + Data.Map.Implicit Language.Scalie.Ast + Language.Scalie.Ast.Definition + Language.Scalie.Ast.Definition.Body + Language.Scalie.Ast.Expression + Language.Scalie.Ast.Module + Language.Scalie.Ast.Pattern + Language.Scalie.Domain.Type other-modules: Paths_scalie hs-source-dirs: src default-extensions: - Safe + ImportQualifiedPost NoImplicitPrelude - ghc-options: -Weverything + StandaloneKindSignatures + RoleAnnotations + ghc-options: -Weverything -Wno-unsafe build-depends: - base >=4.7 && <5 + base + , containers + , text + , vector default-language: Haskell2010 executable scalie-exe @@ -39,12 +52,17 @@ executable scalie-exe hs-source-dirs: app default-extensions: - Safe + ImportQualifiedPost NoImplicitPrelude - ghc-options: -Weverything -threaded -rtsopts -with-rtsopts=-N + StandaloneKindSignatures + RoleAnnotations + ghc-options: -Weverything -Wno-unsafe -threaded -rtsopts -with-rtsopts=-N build-depends: - base >=4.7 && <5 + base + , containers , scalie + , text + , vector default-language: Haskell2010 test-suite scalie-test @@ -55,10 +73,15 @@ test-suite scalie-test hs-source-dirs: test default-extensions: - Safe + ImportQualifiedPost NoImplicitPrelude - ghc-options: -Weverything -threaded -rtsopts -with-rtsopts=-N + StandaloneKindSignatures + RoleAnnotations + ghc-options: -Weverything -Wno-unsafe -threaded -rtsopts -with-rtsopts=-N build-depends: - base >=4.7 && <5 + base + , containers , scalie + , text + , vector default-language: Haskell2010 diff --git a/src/Data/Map/Implicit.hs b/src/Data/Map/Implicit.hs new file mode 100644 index 0000000..f983432 --- /dev/null +++ b/src/Data/Map/Implicit.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE Safe #-} +{-# LANGUAGE TypeFamilies #-} +-- +-- | A Map that derives the keys for the mapping from the items. + +module Data.Map.Implicit (ImplicitMap(), get, ImplicitKeyOf(..), empty) where +import Data.Kind (Type, Constraint) +import Data.Map (Map) +import Data.Map qualified as Map + +type ImplicitMap :: Type -> Type +type role ImplicitMap nominal +newtype ImplicitMap v = ImplicitMap { get :: Map (KeyType v) v } + +type ImplicitKeyOf :: Type -> Constraint + +class ImplicitKeyOf v where + type KeyType v :: Type + keyOf :: v -> KeyType v + +empty :: ImplicitMap v +empty = ImplicitMap Map.empty diff --git a/src/Language/Scalie/Ast.hs b/src/Language/Scalie/Ast.hs deleted file mode 100644 index 3991c50..0000000 --- a/src/Language/Scalie/Ast.hs +++ /dev/null @@ -1 +0,0 @@ -module Language.Scalie.Ast () where diff --git a/src/Language/Scalie/Ast/Definition.hs b/src/Language/Scalie/Ast/Definition.hs new file mode 100644 index 0000000..f7f092d --- /dev/null +++ b/src/Language/Scalie/Ast/Definition.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE Safe #-} +{-# LANGUAGE InstanceSigs #-} +{-# LANGUAGE TypeFamilies #-} +module Language.Scalie.Ast.Definition (Definition(..)) where + +import Data.Kind (Type) +import Data.Text (Text) + +import Language.Scalie.Domain.Type qualified as Scalie.Domain +import Language.Scalie.Ast.Definition.Body (DefinitionBody) +import Data.Map.Implicit (ImplicitKeyOf (KeyType, keyOf)) + +type Definition :: (Type -> Type) -> Type +type role Definition nominal +data Definition f = Definition + { signature :: f Scalie.Domain.Type + -- ^ What is the type + , name :: f Text + -- ^ Which name will be used to refer to this definition + , body :: f (DefinitionBody f) + -- ^ What needs to be evaluated to get the value + } + +instance ImplicitKeyOf (Definition f) where + type KeyType (Definition f) = f Text + keyOf :: Definition f -> KeyType (Definition f) + keyOf = name + diff --git a/src/Language/Scalie/Ast/Definition/Body.hs b/src/Language/Scalie/Ast/Definition/Body.hs new file mode 100644 index 0000000..796c022 --- /dev/null +++ b/src/Language/Scalie/Ast/Definition/Body.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE Trustworthy #-} -- I declare trustworthiness because I only use Vector, I do not call any unsafe functions. +module Language.Scalie.Ast.Definition.Body (DefinitionBody(..)) where + +import Data.Vector (Vector) + +import Language.Scalie.Ast.Expression (Expression) +import Language.Scalie.Ast.Pattern (Pattern) +import Data.Kind (Type) + +type DefinitionBody :: (Type -> Type) -> Type +type role DefinitionBody representational +data DefinitionBody f = DefinitionBody + { arguments :: f (Vector Pattern) + , rhs :: f Expression + } diff --git a/src/Language/Scalie/Ast/Expression.hs b/src/Language/Scalie/Ast/Expression.hs new file mode 100644 index 0000000..061c94e --- /dev/null +++ b/src/Language/Scalie/Ast/Expression.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE Safe #-} +module Language.Scalie.Ast.Expression (Expression(..)) where + +import Prelude (Integer) +import Data.Kind (Type) + +type Expression :: Type +data Expression + = RawInt Integer diff --git a/src/Language/Scalie/Ast/Module.hs b/src/Language/Scalie/Ast/Module.hs new file mode 100644 index 0000000..ca7587f --- /dev/null +++ b/src/Language/Scalie/Ast/Module.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE Safe #-} +{-# LANGUAGE StandaloneKindSignatures #-} +module Language.Scalie.Ast.Module (Module(..)) where + +import Data.Kind (Type) +import Language.Scalie.Ast.Definition (Definition) +import Data.Map.Implicit (ImplicitMap) + +type Module :: (Type -> Type) -> Type +type role Module nominal +data Module f = Module + { definitions :: ImplicitMap (Definition f) + } diff --git a/src/Language/Scalie/Ast/Pattern.hs b/src/Language/Scalie/Ast/Pattern.hs new file mode 100644 index 0000000..57e9ee6 --- /dev/null +++ b/src/Language/Scalie/Ast/Pattern.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE Safe #-} +module Language.Scalie.Ast.Pattern (Pattern(..)) where +import Prelude (Integer) + +data Pattern + = RawInt Integer diff --git a/src/Language/Scalie/Domain/Type.hs b/src/Language/Scalie/Domain/Type.hs new file mode 100644 index 0000000..757d4d2 --- /dev/null +++ b/src/Language/Scalie/Domain/Type.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE Safe #-} +module Language.Scalie.Domain.Type (Type(..)) where + +import Data.Kind qualified + +type Type :: Data.Kind.Type +data Type + = RawInt diff --git a/stack.yaml b/stack.yaml index 885f3d1..d2efd23 100644 --- a/stack.yaml +++ b/stack.yaml @@ -19,6 +19,7 @@ # snapshot: https://example.com/snapshots/2024-01-01.yaml snapshot: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/24/3.yaml +compiler: ghc-9.12.1 # User packages to be built. # Various formats can be used as shown in the example below.