Comments (3)
The error still occurs when I replace (ra,rb)
by pair
and use fst pair
and snd pair
in the rhs.
from idris2.
Each clause is checked in isolation: the catchall does not get to know that Pair a b
has already
been matched.
The solution is to define a view. There are a number of additional subtleties (such as the fact that
the wrong case tree gets generated if you use a with
, or the lack of eta making some definitions
too strict) so you need to define a bunch of auxiliary functions to guide Idris the right way.
This works:
constructor MkRecord
someStuff : List String
data View : Type -> Type where
APair : (a, b : Type) -> View (Pair a b)
Other : (a : Type) -> View a
view : (a : Type) -> View a
view (Pair a b) = APair a b
view x = Other x
tupleToTupleOfRecordsV : View ty -> ty -> Type
tupleToTupleOfRecords : (t : Type) -> (v : t) -> Type
tupleToTupleOfRecordsV (APair ta tb) v = Pair (Record ta (fst v)) $ tupleToTupleOfRecords tb (snd v)
tupleToTupleOfRecordsV (Other ty) v = Record ty v
tupleToTupleOfRecords t v = tupleToTupleOfRecordsV (view t) v
makeTupleRecord : (t : Type) -> (v : t) -> tupleToTupleOfRecords t v -> Record t v
makeTupleRecord t@_ v rs with (view t)
_ | APair ta tb = MkRecord (someStuff (fst rs) <+> (makeTupleRecord tb _ (snd rs)).someStuff)
_ | Other ty = rs
from idris2.
Thank you! I understand. This must be the first situation I encounter where I match, with a catchall, on a variable which affects the type of the result. I can also see that this isn't special to Type
, as I assumed it was; this also gives a similar error:
data X = A | B
t : X -> Type
t A = Int
t B = Bool
f : (x : X) -> t x
f A = 3
f x = True
While processing right hand side of f. Can't solve constraint between: Bool and t x.
match.idr:9:7--9:11
|
9 | f x = True
| ^^^^
Thank you for providing a solution as well! I think the missing piece was that the typechecker needs positive information about how the value was constructed to compute the dependent type, rather than accumulating a negative case list like I thought it might. I guess tupleToTupleOfRecords
using view t
in its body allows the definite constructor of view t
in the case match to carry through into tupleToTupleOfRecordsV
? No worries if it's not quite that simple, I know basically nothing about how the unifier works so can pick it up in my own time.
from idris2.
Related Issues (20)
- 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
- Support type annotations on LHS of a monadic bind `<-` HOT 9
- 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
- Regression in #3328, compilation now hangs sometimes HOT 2
- Syntax for Dictionary types HOT 7
- Erased type-casing function seen as total when it's not
- Case split causes my function to no longer be covering HOT 4
- Searching of `auto` inside pairs introduces ambiguity error between actually same things HOT 3
- Holes at unerased quantity produce bad code
- Parsing Performance & Maintainability. HOT 4
- Names received using as-matching are not reduced under `case`
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.