question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

function doesn't stay polymorphic enough when it is declared to be

See original GitHub issue

I’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:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
johnynekcommented, May 23, 2019

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.

0reactions
johnynekcommented, Jan 23, 2021

this could be related to #650

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found