Skip to content

Commit

Permalink
Refactor builtin Sig into TypeRepr
Browse files Browse the repository at this point in the history
We used to have two indications of a builtins type:

 -  `Sig i o`, which just provided the arity
 -  `BuiltinType i`, which is a closure that checks the type

However, since `Sig` just indicates the arity, it doesn't give us quite enough
information to render the capabilities doc as described in #224.

In this refactor, I extended `Sig` to `TypeRepr` and made it hold more
information: an actual deep embedding of the types.  I also moved this new type
into `BuiltinType` (which is now a record).  This allows convenient construction
of _both_ `TypeRepr` and the checker closure using `🡒` and `out`.
  • Loading branch information
jaspervdj-luminal authored Oct 5, 2020
1 parent 3c0bc89 commit 880789c
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 270 deletions.
1 change: 1 addition & 0 deletions fregot.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Library
Fregot.Eval.Number
Fregot.Eval.TempObject
Fregot.Eval.Value
Fregot.Eval.Value.Conversion
Fregot.Find
Fregot.Interpreter
Fregot.Interpreter.Bundle
Expand Down
2 changes: 0 additions & 2 deletions lib/Fregot/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module Fregot.Builtins
( ToVal (..)
, FromVal (..)

, Sig (..)

, Args (..)
, toArgs

Expand Down
4 changes: 2 additions & 2 deletions lib/Fregot/Builtins/Base64.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ builtins = HMS.fromList
]

encode :: Applicative m => (B.ByteString -> B.ByteString) -> Builtin m
encode f = Builtin (In Out)
encode f = Builtin
(Ty.string 🡒 Ty.out Ty.string) $ pure $
\(Cons text Nil) -> pure . T.decodeUtf8 . f $! T.encodeUtf8 text

decode :: Applicative m => (B.ByteString -> B.ByteString) -> Builtin m
decode f = Builtin (In Out)
decode f = Builtin
(Ty.string 🡒 Ty.out Ty.string) $ pure $
\(Cons t Nil) -> pure . T.decodeUtf8 . f $! T.encodeUtf8 t
Loading

0 comments on commit 880789c

Please sign in to comment.