Comments (9)
Those appear to me to all agree with how let
bindings work (which is a very good thing, as having subtly different syntax for each would be a recipe for confusion)
from idris2.
OK thanks. I'd only suggest parsing what can be parsed currently in let
, even using the same parser code if possible
from idris2.
I've coded this up and the type annotations are working fine, but I need to drop the multiplicities on the pattern matching version. We can still have quantities on bare variables.
There are two problems with quantities on patterns. One is that the syntax is breaking existing code (CI fails). E.g. Network.Socket.Data does:
nullPtr p = do 0 <- primIO $ prim__idrnet_isNull p
which no longer parses because 0
is getting eaten as a quantity.
The second issue is that it won't work at all in the current Idris (this is issue #2513). You can see that while the syntax is accepted for let
, it's not functioning correctly. E.g. y
is unerased in the hole in this code:
blah : Maybe Nat -> Nat
blah x = let 0 (Just y) = x | Nothing => 0 in ?hole
Issue #2513 is fixed in PR #2535 which we closed pending new core. I'm happy to revive that work separately, if and when we're ready to merge it.
But the type annotations and quantities on variables do work. I can PR this after backing off the pattern quantities. I'll leave the previous commit in the branch history.
from idris2.
It also needs to be thought how this feature would interplay with pattern matching and shortcut alternatives:
do (a, b) : (X, Y) <- foo
1 (c, d, e) : (A, B, C) <- bar
5 : Nat <- baz
| 6 => unbaz
| _ => unbaf
unfoo
from idris2.
I don't think the 5
example is consistent with the current behavior of let
. Because of parsing for multiplicities, let
will give a parse error for:
let 5 := ...
and
let 5 : Nat := ...
but accepts:
let (5) := ...
The parser for multiplicity could be tweaked to only have this behavior for 0
and 1
, but it might rule out having other multiplicities in the future.
from idris2.
what about let 5 : Nat =
?
from idris2.
Currently that is a parse error:
1: Couldn't parse declaration.
src.Temp:12:13--12:14
08 | -- then S (countFst (x :: zs) | zs)
09 | -- else countFst (x :: zs) | zs
10 |
11 | foo : Nat -> Nat
12 | foo x = let 5 : Nat = x | _ => 42 in 6
^
... (6 others)
If you put parens around the 5, it parses, because the parser for multiplicity
doesn't see the number.
from idris2.
Because of this - it maybe parses a number and then decides its an error if there is a number there that is not 0 or 1. Arguably correct if we plan to support other numbers someday?
multiplicity : OriginDesc -> EmptyRule RigCount
multiplicity fname
= case !(optional $ decorate fname Keyword intLit) of
(Just 0) => pure erased
(Just 1) => pure linear
Nothing => pure top
_ => fail "Invalid multiplicity (must be 0 or 1)"
If we do want a bare 5 to work, this would have to change to succeed without consuming anything for integers other than 0 or 1.
from idris2.
Arguably correct if we plan to support other numbers someday?
Maybe, but someday we will have support of whole expressions for quantities, and this will anyway cause similar problems on the next level
from idris2.
Related Issues (20)
- [ perf ] type-level evalutaion of `Prelude.elem` is slow compared to the naïve implementation
- Loss of Linearity in Interaction of Abstract Interfaces and Linear State Transformer Monad HOT 5
- Is it safe to pass a GC'ed pointer to C?
- Underscore name of an implicit argument in a signature of an interface function does not work
- Chez backend is too naive on the value of `CHEZ` environment variable
- unification failure between if then else statements when using isYes (decEq n a) as the condition HOT 2
- Add error message with missing fixity namespace
- Execution and compilation hangs indefintely HOT 3
- Loading file in ide-mode changes working directory and causes errors on later actions
- Make output of ide-mode `:interpret` consistent to always return consistent datatype (String)
- Inconsistent error message when finding more than one implementation of an interface
- Reconstructing a (structurally smaller) aggregate from pattern-matched components trips up the totality checker HOT 8
- Incremental compilation includes some but not all metas
- Test idris2/reflection/reflection024 fails due to not accounting for locales
- Nested code blocks are ignored in literate markdown HOT 1
- Bootstrap with Racket error: `raco: Unrecognized command: exe` HOT 3
- Why quoted values are EmptyFC?
- Totality checker inconsistency when using Inf HOT 2
- Case split doesn't detect cases when working inside a namespace
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 idris2.