Skip to content

Instantly share code, notes, and snippets.

@chrisdone-artificial
Created January 7, 2025 15:39
Show Gist options
  • Save chrisdone-artificial/47654517f8d5e9ba83c2b2bbd751c03b to your computer and use it in GitHub Desktop.
Save chrisdone-artificial/47654517f8d5e9ba83c2b2bbd751c03b to your computer and use it in GitHub Desktop.
stream spec.diff
6f81ffa2114bd81c18229f2958299953021e77ca HEAD -> cd/2025-01-07-streamspec
Author: Chris Done <[email protected]>
Date: Tue Jan 7 15:38:48 2025 +0000
Support stream spec
1 file changed, 18 insertions(+)
src/Hell.hs | 18 ++++++++++++++++++
Modified src/Hell.hs
diff --git a/src/Hell.hs b/src/Hell.hs
index 39f88ff..bb3cad1 100644
--- a/src/Hell.hs
+++ b/src/Hell.hs
@@ -462,6 +462,7 @@ data Binding = Singleton String | Tuple [String]
data Forall where
NoClass :: (forall (a :: Type). TypeRep a -> Forall) -> Forall
SymbolOf :: (forall (a :: Symbol). TypeRep a -> Forall) -> Forall
+ StreamTypeOf :: (forall (a :: StreamType). TypeRep a -> Forall) -> Forall
ListOf :: (forall (a :: List). TypeRep a -> Forall) -> Forall
OrdEqShow :: (forall (a :: Type). (Ord a, Eq a, Show a) => TypeRep a -> Forall) -> Forall
Monadic :: (forall (m :: Type -> Type). (Monad m) => TypeRep m -> Forall) -> Forall
@@ -584,6 +585,8 @@ tc (UForall _ _ _ fall _ _ reps0) _env = go reps0 fall
| Just Type.HRefl <- Type.eqTypeRep (typeRepKind rep) (typeRep @List) = go reps (f rep)
go (SomeTypeRep rep : reps) (SymbolOf f)
| Just Type.HRefl <- Type.eqTypeRep (typeRepKind rep) (typeRep @Symbol) = go reps (f rep)
+ go (SomeTypeRep rep : reps) (StreamTypeOf f)
+ | Just Type.HRefl <- Type.eqTypeRep (typeRepKind rep) (typeRep @StreamType) = go reps (f rep)
go (StarTypeRep rep : reps) (OrdEqShow f) =
if
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Int) -> go reps (f rep)
@@ -621,6 +624,7 @@ tc (UForall _ _ _ fall _ _ reps0) _env = go reps0 fall
showR = \case
NoClass {} -> "NoClass"
SymbolOf {} -> "SymbolOf"
+ StreamTypeOf {} -> "StreamTypeOf"
ListOf {} -> "ListOf"
OrdEqShow {} -> "OrdEqShow"
Monadic {} -> "Monadic"
@@ -1123,6 +1127,9 @@ supportedTypeConstructors =
("Tree", SomeTypeRep $ typeRep @Tree),
("Value", SomeTypeRep $ typeRep @Value),
("ProcessConfig", SomeTypeRep $ typeRep @ProcessConfig),
+ ("StreamType", SomeTypeRep $ typeRep @StreamType),
+ ("STInput", SomeTypeRep $ typeRep @STInput),
+ ("STOutput", SomeTypeRep $ typeRep @STOutput),
("()", SomeTypeRep $ typeRep @()),
-- Internal, hidden types
@@ -1391,6 +1398,13 @@ polyLits =
[pure $ TH.ConP 'TypeRep [TH.SigT (TH.VarT v) (TH.ConT v_k)] []]
rest
)
+ (TH.KindedTV v TH.SpecifiedSpec (TH.ConT v_k)) | v_k == ''StreamType -> \rest ->
+ TH.appE
+ (TH.conE 'StreamTypeOf)
+ ( TH.lamE
+ [pure $ TH.ConP 'TypeRep [TH.SigT (TH.VarT v) (TH.ConT v_k)] []]
+ rest
+ )
t -> error $ "Did not expect this type of variable! " ++ show t
)
finalExpr
@@ -1406,6 +1420,10 @@ polyLits =
in derivePrims
[|
do
+ "Process.runProcess" runProcess :: forall a b c. ProcessConfig a b c -> IO ExitCode
+ "Process.runProcess_" runProcess_ :: forall a b c. ProcessConfig a b c -> IO ()
+ "Process.setStdout" setStdout :: forall stdin stdout stdout' stderr. StreamSpec 'STOutput stdout' -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout' stderr
+ "Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
-- Records
"hell:Hell.ConsR" ConsR :: forall (k :: Symbol) a (xs :: List). a -> Record xs -> Record (ConsL k a xs)
"Record.get" _ :: forall (k :: Symbol) a (t :: Symbol) (xs :: List). Tagged t (Record xs) -> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment