function doesn't stay polymorphic enough when it is declared to be
See original GitHub issueI’ll take another pass and simplify this later but I thought I’d post this in case the solution is obvious
This code:
package RecordSet
enum RowEntry[w]:
REBool(value: w[Bool])
REInt(value: w[Int])
REString(value: w[String])
struct RecordField[t](name: String, to_entry: forall w. w[t] -> RowEntry[w])
struct RecordValue[t](value: t)
struct RecordGetter[shape, t](f: forall w. shape[w] -> w[t])
struct RecordSet[shape](fields: shape[RecordField], rows: List[shape[RecordValue]], getters: shape[RecordGetter[shape]])
def restructure(RecordSet(fields, rows, getters), f: shape1[RecordGetter[shape1]] -> (forall w. shape1[w] -> shape2[w], shape2[RecordGetter[shape2]])) -> RecordSet[shape2]:
(reshaper, new_getters) = f(getters)
RecordSet(reshaper(fields), rows.map_List(reshaper), new_getters)
results in:
-----------------------------------------------------------------------------
in file: test_workspace/recordset.bosatsu, package RecordSet, type RecordField does not unify with type RecordValue
14|def restructure(RecordSet(fields, rows, getters), f: shape1[RecordGetter[shape1]] -> (forall w. shape1[w] -> shape2[w], shape2[RecordGetter[shape2]])) -> RecordSet[shape2]:
15| (reshaper, new_getters) = f(getters)
16| RecordSet(reshaper(fields), rows.map_List(reshaper), new_getters)
^^^^^^^^
even though reshaper
should have type forall w. shape1[w] -> shape2[w]
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Chapter 5 Polymorphism and its limitations - OCaml
This chapter covers more advanced questions related to the limitations of polymorphic functions and types. There are some situations in OCaml where the...
Read more >Parametrically polymorphic modules - ocaml - Stack Overflow
Is there any way to define a "parametrically polymorphic" module of type Monad that would give parametrically polymorphic functions like return ...
Read more >polymorphic-functions - Quickdocs
Subtype Polymorphism is supported in the sense that once a polymorph is defined, then when a call to it is being compiled, then...
Read more >CSE341 Lecture Notes 6: Polymorphic type inference in ML
When doing type inference by hand, we can approximate this algorithm by assigning a fresh type variable to each bound name and each...
Read more >SML '97 Types and Type Checking - Standard ML of New Jersey
So in this case the type will not be generalized and y will not have a polymorphic type. In fact, if the declaration...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
glad you have a work around, but that’s obviously annoying. It can see that either of those two types would work, but somehow it can’t widen them to those types at the use site.
This would be nice to improve. Thanks for working through it.
this could be related to #650