Skip to content

Commit 4604cf4

Browse files
author
Your Name
committed
Add basic bijection to/from FD.UTerm
1 parent 8ea5a67 commit 4604cf4

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

src/Hell.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{-# LANGUAGE BlockArguments #-}
44
{-# LANGUAGE CPP #-}
55
{-# LANGUAGE DataKinds #-}
6-
{-# LANGUAGE DeriveFoldable #-}
6+
{-# LANGUAGE DeriveFoldable, DeriveGeneric #-}
77
{-# LANGUAGE DeriveFunctor #-}
88
{-# LANGUAGE DeriveTraversable #-}
99
{-# LANGUAGE ExistentialQuantification, DuplicateRecordFields, NoFieldSelectors #-}
@@ -43,6 +43,8 @@
4343
module Main (main, specMain) where
4444

4545
#if __GLASGOW_HASKELL__ >= 906
46+
import qualified Control.Unification as FD
47+
import GHC.Generics (Generic1)
4648
import Control.Monad
4749
#endif
4850

@@ -2636,6 +2638,30 @@ temp_withSystemTempDirectory template action = Temp.withSystemTempDirectory (Tex
26362638
process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c
26372639
process_setWorkingDir filepath = Process.setWorkingDir (Text.unpack filepath)
26382640

2641+
--------------------------------------------------------------------------------
2642+
-- unification-fd compatibility layer
2643+
2644+
data Ty a
2645+
= TyApp a a
2646+
| TyFun a a
2647+
| TyCon SomeTypeRep
2648+
deriving (Functor, Traversable, Foldable, Eq, Ord, Show, Generic1)
2649+
2650+
-- <bijection>
2651+
irep_to_uterm :: IRep v -> FD.UTerm Ty v
2652+
irep_to_uterm = \case
2653+
IVar v -> FD.UVar v
2654+
IApp f x -> FD.UTerm (TyApp (irep_to_uterm f) (irep_to_uterm x))
2655+
IFun f x -> FD.UTerm (TyFun (irep_to_uterm f) (irep_to_uterm x))
2656+
ICon t -> FD.UTerm $ TyCon t
2657+
uterm_to_irep :: FD.UTerm Ty v -> IRep v
2658+
uterm_to_irep = \case
2659+
FD.UVar v -> IVar v
2660+
FD.UTerm (TyApp f x) -> IApp (uterm_to_irep f) (uterm_to_irep x)
2661+
FD.UTerm (TyFun f x) -> IFun (uterm_to_irep f) (uterm_to_irep x)
2662+
FD.UTerm (TyCon t) -> ICon t
2663+
-- </bijection>
2664+
26392665
--------------------------------------------------------------------------------
26402666
-- Inference type representation
26412667

0 commit comments

Comments
 (0)