From 67c88df53ad826396d4415e20d3c643bd3eaade2 Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Wed, 6 Mar 2024 10:07:00 -0700 Subject: [PATCH] derive --- src/Rlp/AltSyntax.hs | 6 +++++- src/Rlp/HindleyMilner.hs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Rlp/AltSyntax.hs b/src/Rlp/AltSyntax.hs index 9eec275..946c2cb 100644 --- a/src/Rlp/AltSyntax.hs +++ b/src/Rlp/AltSyntax.hs @@ -22,6 +22,8 @@ import Data.Functor.Sum import Control.Comonad.Cofree import Data.Fix import Data.Function (fix) +import GHC.Generics (Generic(..)) +import Data.Hashable import Control.Lens import Text.Show.Deriving @@ -53,7 +55,9 @@ data Type b = VarT b | ConT b | AppT (Type b) (Type b) | FunT - deriving Show + deriving (Show, Eq, Generic) + +instance (Hashable b) => Hashable (Type b) instance Core.HasArrowSyntax (Type b) (Type b) (Type b) where _arrowSyntax = prism make unmake where diff --git a/src/Rlp/HindleyMilner.hs b/src/Rlp/HindleyMilner.hs index 3675ddc..92ae8a5 100644 --- a/src/Rlp/HindleyMilner.hs +++ b/src/Rlp/HindleyMilner.hs @@ -6,13 +6,20 @@ module Rlp.HindleyMilner ) where -------------------------------------------------------------------------------- -import Control.Lens hiding (Context', Context) +import Control.Lens hiding (Context', Context, (:<)) import Control.Monad.Errorful import Data.Text qualified as T import Data.Pretty import Text.Printf +import Data.Hashable +import Data.HashMap.Strict (HashMap) +import Data.HashMap.Strict qualified as H +import Data.HashSet (HashSet) +import Data.HashSet qualified as S +import GHC.Generics (Generic(..), Generically(..)) import Data.Functor +import Data.Fix import Control.Comonad.Cofree import Compiler.RlpcError @@ -54,3 +61,28 @@ type HMError = Errorful TypeError infer = undefined check = undefined +type Context' = HashMap PsName (Type PsName) + +data Constraint = Equality (Type PsName) (Type PsName) + deriving (Eq, Generic, Show) + +instance Hashable Constraint + +type Constraints = HashSet Constraint + +data PartialJudgement = + PartialJudgement Constraints Context' + + deriving (Generic, Show) + deriving (Semigroup, Monoid) + via Generically PartialJudgement + +fixCofree :: (Functor f, Functor g) + => Iso (Fix f) (Fix g) (Cofree f ()) (Cofree g b) +fixCofree = iso sa bt where + sa = foldFix (() :<) + bt (_ :< as) = Fix $ bt <$> as + +gather :: Context' -> RlpExpr PsName -> HMError (Type PsName, Constraints) +gather = undefined +