dino 0.1 → 0.1.1
raw patch · 3 files changed
+48/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +29/−6
- dino.cabal +2/−2
- examples/README.hs +17/−6
README.md view
@@ -7,7 +7,7 @@ Syntactic conveniences -------------------------------------------------------------------------------- -The module [`Dino.Expression`](https://hackage.haskell.org/package/dino/docs/Dino-Expression.html) redefines many identifiers from the prelude, so users are advised to hide the prelude when importing it. This can be done, for example, using the `NoImplicitPrelude` language extension. The main module, [`Dino`](https://hackage.haskell.org/package/dino/docs/Dino.html), exports both `Dino.Expression` and `Dino.Prelude`, where the latter is a subset of the standard prelude plus a few extra definitions.+The module [Dino.Expression](https://hackage.haskell.org/package/dino/docs/Dino-Expression.html) redefines many identifiers from the prelude, so users are advised to hide the prelude when importing it. This can be done, for example, using the `NoImplicitPrelude` language extension. The main module, [Dino](https://hackage.haskell.org/package/dino/docs/Dino.html), exports both `Dino.Expression` and `Dino.Prelude`, where the latter is a subset of the standard prelude plus a few extra definitions. Dino provides a newtype wrapper, `Exp`, which allows EDSL terms to be used directly as numbers and strings; for example: @@ -38,7 +38,7 @@ ( Otherwise --> "storm" ) ``` -Browse the [`Dino.Expression`](https://hackage.haskell.org/package/dino/docs/Dino-Expression.html) documentation to find different variations on `cases`, including a version for matching on enumerations without a fall-through case.+Browse the [Dino.Expression](https://hackage.haskell.org/package/dino/docs/Dino-Expression.html) documentation to find different variations on `cases`, including a version for matching on enumerations without a fall-through case. ### A `Maybe`-like monad @@ -97,7 +97,7 @@ ### Intensional analysis -Dino has special support for intensional interpretation of higher-order constructs (i.e. interpretations that inspect the syntax).+Dino has special support for intensional interpretation of higher-order constructs (i.e. interpretations that inspect the syntax). The general idea is introduced in [Oleg Kiselyov's notes](http://okmij.org/ftp/tagless-final/course/TTFdBHO.hs). Consider the following two classes: @@ -120,7 +120,10 @@ The former is the class that is exposed to the EDSL user. It provides a convenient higher-order construct for sharing values. Here is an example of its use: ```haskell-ex2 :: Exp e Double -> Exp e Double+ex2 ::+ (ConstExp e, NumExp e, CompareExp e, CondExp e, LetExp e)+ => Exp e Double+ -> Exp e Double ex2 a = letE "x" expensive $ \x -> if a > 10 then x*2@@ -157,8 +160,8 @@ But what about adding new higher-order constructs? Then one must go through the work of defining an instance such as the one for `LetExp (Intensional e)` above. Fortunately, defining such instances is made very easy by the following function: ```haskell-unbind- :: (VarExp e, DinoType a)+unbind ::+ (VarExp e, DinoType a) => Text -- ^ Variable base name -> (Intensional e a -> Intensional e b) -- ^ Body parameterized by its free variable -> (Text, Intensional e b) -- ^ Generated variable and function body@@ -167,3 +170,23 @@ It takes a body represented as a function, and returns a body as an open expression along with the generated variable name. This name is guaranteed not to lead to capturing, as long all binders are generated using the same method. There is also `unbind2`, for constructs that introduce two local variables. For the curious reader, `unbind` is implemented using the technique in [Using Circular Programming for Higher-Order Syntax](https://emilaxelsson.github.io/documents/axelsson2013using.pdf).++### Parallel interpretation++The `(:×:)` type allows two interpretations to run in parallel. This type derives many syntactic classes automatically:++```haskell+instance (ConstExp e1, ConstExp e2) => ConstExp (e1 :×: e2)+instance (NumExp e1, NumExp e2) => NumExp (e1 :×: e2)+...+```++However, it is not possible to give such general instances for classes with higher-order constructs (e.g. `LetExp`). Instead, there are instances for intensional classes, such as this one:++```haskell+instance (LetIntensional e1, LetIntensional e2) => LetIntensional (e1 :×: e2)+```++As seen earlier, we can derive `LetExp` from `LetIntensional` by using the `Intensional` wrapper. So, in order to obtain a parallel interpretation for `LetExp`, we simply use the type `Intensional (e1 :×: e2)`, where `e1` and `e2` are the interpretations we want to run. (Of course, `(:×:)` can be nested in order to run more than two interpretations in parallel.)++Note that we cannot run standard evaluation as a parallel interpretation. This is because the monads for standard evaluation (e.g. `Identity` or `Maybe`) implement `LetExp` but not `LetIntensional`. In order to do evaluation in a parallel setting, use the type `EvalEnv`, which evaluates using a variable environment.
dino.cabal view
@@ -1,8 +1,8 @@ name: dino-version: 0.1+version: 0.1.1 synopsis: A convenient tagless EDSL description: For more information, see the- <https://github.com/emilaxelsson/trackit/blob/master/README.md README>.+ <https://github.com/emilaxelsson/dino/blob/master/README.md README>. license: BSD3 license-file: LICENSE author: Emil Axelsson
examples/README.hs view
@@ -89,14 +89,25 @@ -> Maybe a evalSafeDiv = fromSafeDiv . unExp -ex2 :: (ConstExp e, NumExp e, FracExp e, LogicExp e, CompareExp e) => Exp e Double-ex2 = 1+2/3+exDiv1 :: (ConstExp e, NumExp e, FracExp e, LogicExp e, CompareExp e) => Exp e Double+exDiv1 = 1+2/3 -ex3 :: (ConstExp e, NumExp e, FracExp e, LogicExp e, CompareExp e) => Exp e Double-ex3 = 1+2/0+exDiv2 :: (ConstExp e, NumExp e, FracExp e, LogicExp e, CompareExp e) => Exp e Double+exDiv2 = 1+2/0 +ex2 ::+ (ConstExp e, NumExp e, CompareExp e, CondExp e, LetExp e)+ => Exp e Double+ -> Exp e Double+ex2 a = letE "x" expensive $ \x ->+ if a > 10+ then x*2+ else x*3+ where+ expensive = a*a*a*a*a*a*a*a + -------------------------------------------------------------------------------- tests = do@@ -106,5 +117,5 @@ print $ eval $ foo 11 12 print $ eval $ foo 11 0 fooExp- print $ evalSafeDiv ex2- print $ evalSafeDiv ex3+ print $ evalSafeDiv exDiv1+ print $ evalSafeDiv exDiv2