packages feed

dovetail 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+68/−5 lines, 4 files

Files

+ README.md view
@@ -0,0 +1,21 @@+# Dovetail++Dovetail is a general-purpose PureScript interpreter written in Haskell.++It has excellent support for interop with Haskell code via PureScript's foreign function interface, along with a high-level Haskell API for integrating such code.++As such, it is possible to write low-level or domain-specific code in Haskell, and then to write the "glue code" in PureScript. In this way, Dovetail is a tool for reusing the frontend of the PureScript compiler (its syntax and type checker) to build domain specific languages in Haskell.++## Getting Started++To understand the library and how to use it, it is recommended that you read through the Haddock documentation, alongside the provided examples:++- Hackage documentation+  - [`dovetail` on Hackage](https://hackage.haskell.org/package/dovetail)+  - [`dovetail-aeson` on Hackage](https://hackage.haskell.org/package/dovetail-aeson)+  - [Haddocks on GitHub Pages](http://functorial.com/dovetail)+- Examples:+  - [JSON query language](https://github.com/paf31/dovetail/blob/main/examples/query-json/Main.hs)+  - [Fake data generator](https://github.com/paf31/dovetail/blob/main/examples/fake-data/Main.hs)+  +You can build the code and examples in this repository using `stack build`, and run the test suite with `stack test`.
dovetail.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 8e19e51ff69a860795e7b3909da11ef1e97bfc1266ab5075a42721d37c2f5f23+-- hash: 9fd50996176509cb603dec378bf3364eb1637ccbf382d164e1e386e97d2e5da8  name:           dovetail-version:        0.1.0.0+version:        0.1.1.0 synopsis:       A PureScript interpreter with a Haskell FFI. description:    Dovetail is a general-purpose PureScript corefn interpreter with an FFI to Haskell. Please see the README on GitHub at <https://github.com/paf31/dovetail#readme>, or check out the examples directory, to learn how to use the library. category:       Language@@ -19,6 +19,8 @@ license:        BSD3 license-file:   LICENSE build-type:     Simple+extra-source-files:+    README.md  source-repository head   type: git
src/Dovetail/Evaluate.hs view
@@ -333,7 +333,7 @@   default fromValue :: (G.Generic a, ToObject m (G.Rep a)) => Value m -> EvalT m a   fromValue = genericFromValue defaultObjectOptions   -instance MonadFix m => ToValue m (Value m) where+instance (MonadFix m, m ~ m') => ToValue m (Value m') where   toValue = id   fromValue = pure 
src/Dovetail/Prelude.hs view
@@ -2,7 +2,9 @@ {-# LANGUAGE FlexibleContexts    #-} {-# LANGUAGE GADTs               #-} {-# LANGUAGE ImportQualifiedPost #-}+{-# LANGUAGE LambdaCase          #-} {-# LANGUAGE OverloadedStrings   #-}+{-# LANGUAGE PatternSynonyms     #-} {-# LANGUAGE RankNTypes          #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications    #-}@@ -11,15 +13,18 @@ module Dovetail.Prelude where    import Control.Monad.Fix (MonadFix)+import Control.Monad.Error.Class (catchError, throwError) import Data.Char (chr, ord) import Data.Text qualified as Text import Data.Vector qualified as Vector-import Dovetail.Evaluate (ToValue, ToValueRHS)-import Dovetail.FFI (FFI(..))+import Dovetail.Evaluate (ToValue, ToValueRHS, toValue)+import Dovetail.FFI (FFI(..), ForeignImport(..)) import Dovetail.FFI.Builder (array, boolean, char, int, string, number, (~>)) import Dovetail.FFI.Builder qualified as FFI+import Dovetail.FFI.Internal (forAll, function) import Dovetail.Types import Language.PureScript qualified as P+import Language.PureScript.Constants.Prim (pattern Partial)  stdlib :: MonadFix m => [FFI m] stdlib = @@ -31,6 +36,7 @@   , preludeInt   , preludeBoolean   , preludeDebug+  , preludePartial   ]  prelude :: MonadFix m => FFI m@@ -144,6 +150,40 @@     FFI.foreignImport (P.Ident "crash")       (\a -> string ~> a)       (throwErrorWithContext . OtherError)+      +preludePartial :: forall m. MonadFix m => FFI m+preludePartial = +  let partial ty =+        P.ConstrainedType P.nullSourceAnn +          (P.Constraint P.nullSourceAnn Partial [] [] Nothing) +          ty+   in FFI+        { ffi_moduleName = P.ModuleName "Prelude.Partial"+        , ffi_values = +            [ ForeignImport+                { fv_name = P.Ident "unsafePartial"+                , fv_type = +                    forAll \a -> partial a `function` a+                , fv_value =+                    toValue @m @((Value m -> EvalT m (Value m)) -> EvalT m (Value m)) +                      \f -> f (Object mempty)+                }+            , ForeignImport+                { fv_name = P.Ident "fromPartial"+                , fv_type = +                    forAll \a -> +                      a `function` (partial a `function` a)+                , fv_value =+                    toValue @m @(Value m -> (Value m -> EvalT m (Value m)) -> EvalT m (Value m)) +                      \def f -> do+                        catchError (f (Object mempty)) \case+                          EvaluationError { errorType = InexhaustivePatternMatch _ } ->+                            pure def+                          err ->+                            throwError err+                }+            ]+        }  eqOps    :: (ToValue m a, ToValueRHS m (EvalT m a), Eq a)