Comments (4)
Good point. I should pick a different type for the first exercise until the tutorial explains Natural
numbers
from dhall-haskell.
Also, to answer your question: yes you do need the +
prefix for Natural
numbers. They are a distinct type from Integer
s. See: https://hackage.haskell.org/package/dhall-1.0.1/docs/Dhall-Tutorial.html#g:14
from dhall-haskell.
It does lead to some confusing errors for newbies.
#:global-project hephaestus$ echo "1 + 1" | dhall
Use "dhall --explain" for detailed errors
Error: ❰+❱ only works on ❰Natural❱s
1 + 1
(stdin):1:1
#:global-project hephaestus$ echo "1+1" | dhall
Use "dhall --explain" for detailed errors
Error: Not a function
1+1
(stdin):1:1
#:global-project hephaestus$ echo "+1++1" | dhall
Use "dhall --explain" for detailed errors
Error: ❰++❱ only works on ❰Text❱
+1++1
(stdin):1:1
#:global-project hephaestus$ echo "+1+ +1" | dhall
Natural
+2
Not sure what would be better. I'd say to require +
or -
for Integer
s instead of Natural
s but what do you do with 0
?
from dhall-haskell.
@echatav: So in the first case, the --explain
flag would go into detail about how you can't add Integer
s:
$ dhall --explain
1 + 1
<Ctrl-D>
Error: ❰+❱ only works on ❰Natural❱s
Explanation: The ❰+❱ operator expects two arguments that have type ❰Natural❱
For example, this is a valid use of ❰+❱:
┌─────────┐
│ +3 + +5 │
└─────────┘
You provided this argument:
↳ 1
... which does not have type ❰Natural❱ but instead has type:
↳ Integer
Some common reasons why you might get this error:
● You might have tried to use an ❰Integer❱, which is not allowed:
┌─────────────────────────────────────────┐
│ λ(x : Integer) → λ(y : Integer) → x + y │ Not valid
└─────────────────────────────────────────┘
You can only use ❰Natural❱ numbers
● You might have mistakenly used an ❰Integer❱ literal, which is not allowed:
┌───────┐
│ 2 + 2 │ Not valid
└───────┘
You need to prefix each literal with a ❰+❱ to transform them into ❰Natural❱
literals, like this:
┌─────────┐
│ +2 + +2 │ Valid
└─────────┘
────────────────────────────────────────────────────────────────────────────────
1 + 1
(stdin):1:1
The contract for error messages is that --explain
should provide enough information.
I can improve the error message for the second case by special-casing the error to notice if the function is an Integer
or a Natural
and the argument is a Natural
and provide a hint that the user might want to put spaces around the +
For the third case, I think the error message is clear even without --explain
: the compiler is obviously parsing the ++
as the Text append operator. It might be disconcerting but I don't think it's confusing
from dhall-haskell.
Related Issues (20)
- Error generating docs
- combine `let` bindings in `dhall format` HOT 1
- Support request for `aeson` 2.2 in `dhall` HOT 2
- dhall-to-yaml does not properly quote strings HOT 1
- Can not install dhall-lsp-server HOT 2
- Allow hnix 0.17
- Hackage build failed for dhall-toml-1.0.3
- Get back into Stackage Nightly with GHC 9.8 HOT 1
- Missing binaries in release HOT 1
- Hackage release for dhall-lsp-server HOT 1
- Build failure on GHC 9.8.1: 'Illegal invisible type variable binder'
- Report imports HOT 2
- dhall-docs: Prelude.head: empty list
- Suggesting a new construct for dealing with optional fields in Dhall defaults
- dhall-json bound on aeson can be relaxed
- Questions regarding the right strategy for upgrading to ghc-9.8
- Build failure on macos-latest stack.yaml HOT 3
- Is there a specification for dhall-to-{json,yaml} and {json,yaml}-to-dhall? HOT 1
- Pretty-printer: escape unprintable characters HOT 2
- `with` expressions regressed HOT 8
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 dhall-haskell.