Comments (14)
The DSL.Expression is a phantom type for DAG.Expression:
newtype Expression a = Expression { unExpression :: DAG.Expression }
The phantom type guaranties type correct DAGs. The only point where I'm a bit uncertain if this works is in the Num instance.
from frp-arduino.
Removed discussion of solution from title.
from frp-arduino.
@rickardlindberg , yes I'm aware it's a phantom type. I'm unsure how it asserts the correctness of DAG`'s. For example, nothing is stopping me from defining
foo :: DSL.Expression Bool
foo = DAG.Expression $ ListConstant []
from frp-arduino.
If you only use the functions in the DSL module, you can only create correct DAGs.
In the example you showed, you can indeed create invalid DAGs, but then you need to use functions from the DAG module.
So the phantom type ensures that users of the DSL create correct DAGs. But it does not ensure that creators of the DSL (us) create correct DAGs.
Maybe GADTs will also solve that problem. In that case, I think it's a better option.
This article seems to prefer phantom types over GATSs: http://augustss.blogspot.se/2007/06/representing-dsl-expressions-in-haskell.html
from frp-arduino.
@rickardlindberg yes, I think its slightly unreasonable to assume that the user (including us) will never need to write extensions to the DSL. The GADT ensure that this is possible.
Another concern of mine is whether the code generator uses the types consistently. I suspect it does given that it works, but this acts as a test to make sure they remain consistent.
from frp-arduino.
Just read the article. The big concern seems to be that GADTs isn't standard.
This is a bit of a judgment call. I don't mind being tied to ghc, given its general pervasiveness.
The other sticking point is that the evaluator now needs a typed environment. I don't think this is an issue since we are targeting C which is typed.
from frp-arduino.
Just read this and found it quite helpful:
https://en.wikibooks.org/wiki/Haskell/GADT
from frp-arduino.
@rickardlindberg exactly, we just replace eval
with a compiler in CodeGen
. GADTs would allow us to enforce type safety all the way down.
from frp-arduino.
From Lennart's article:
GADTs is really the way to go, but it has the disadvantage of not being standard Haskell. It can also get somewhat cumbersome when we have variables; the evaluator now needs a typed environment.
I don't understand the second part about cumbersome with variables.
from frp-arduino.
@rickardlindberg I think he's referring to having a variable constructor in your DSL:
data Expr a where
IntConst :: Int -> Expr Int
Variable :: Expr a -> Expr a
or alternatively (depending on how it needs to be encoded)
data Ref a = Ref a
data Expr a where
IntConst :: Int -> Expr Int
Variable :: Expr a -> Expr (Ref a)
He the talks about
the evaluator now needs a typed environment.
Which was exactly the point of the GADTs! (as in the wiki link). I think its a pretty bad argument.
The whole ghc exclusive part sure, but not because I'm worried about a typed evaluation....that's what I want unless I'm emulating an untyped language (like python)
from frp-arduino.
In the DAG, we have Input Int
which is a variable of arbitrary type. Will that be hard to express using GADT?
I don't undertstand your example:
Variable :: Expr a -> Expr a
Don't you need a name of some kind? Or the index in Input Int
?
Probably I should study GADTs more.
from frp-arduino.
Sure, it'd probably make sense to use an identifier for the variable
i.e.
Variable :: Identifier -> Expression a -> Expression a
As a GADT, Input Int
Because Input :: Int -> Expression Int
That main point is that one can specify the output type.
from frp-arduino.
But in the case of Input
, we don't know the type beforehand. An input can be of any type.
Anyway, late night here now, so I should probably get some sleep now and think more about this tomorrow :-)
from frp-arduino.
haha, ok.
Also, I seem to have misunderstood what input was. Yes in the case of any type you would just define
Input :: Int -> Expression a
Then the first use of it will set the type.
I.E.
myInput :: Expression Int
myInput = Input 0
which is the exact same situation as the phantom type.
from frp-arduino.
Related Issues (20)
- What is your interest in frp-arduino? HOT 5
- Problem: PWM missing from API HOT 5
- Problem: IC2 missing from API HOT 2
- Problem: Num TypeClass not finished HOT 1
- Problem: Folds only work for numbers
- Problem: Arduino makefile is overkill
- Issue handling process HOT 4
- How much optimization can we get from gcc? HOT 1
- Problem: LCD can only output static text
- Question: Could we use linear types to avoid duplicate resource allocation HOT 5
- Question: Potentially add support for random sampling HOT 2
- Question: Reading inputs via interrupts HOT 1
- Question: Why is there no pin9? HOT 3
- Project status HOT 7
- How would one add new Arduino microcontrollers HOT 7
- API Documentation Missing HOT 15
- test Fails Because of Missing Files in dist HOT 3
- Not able to run make succesfully HOT 5
- Support for stack HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frp-arduino.