InvalidInstanceHead
error can be subverted via vacuous fundep
#4474
Labels
InvalidInstanceHead
error can be subverted via vacuous fundep
#4474
Description
An instance head containing the empty row
()
normally causes anInvalidInstanceHead
. As the compiler instructs, by adding appropriate fundeps to the class one can make the instance valid. Surprisingly, one can also make the instance valid by adding a fundep of the forma -> a
wherea
is the type variable being instantiated to the empty row()
.To Reproduce
Run the following program in Purescript 0.15.8 (online playground):
Expected behavior
The instance with the vacuous fundep
a -> a
should (?) also cause anInvalidInstanceHead
errorAdditional context
The docs for
InvalidInstanceHead
say "when you see this error, it's because you're trying to write an instance of a given class that pattern matches on some row type [...] there isn't really a sensible way to match on row."I don't know if this is worth anything, but it's kinda unclear to me what's unsensible about matching on row types, and I can't find an explanation online. In fact, by abusing this "vacuous fundeps circumvents
InvalidInstanceHead
" bug I was able to write asplit
function which can split a record into subrecords decided at compile time. eg,This function is quite handy in a project I'm working on. Of course it could be implemented with
RowToList
, but I think that would requireunsafeCoerce
whereas the current implementation does not.PureScript version
0.15.8
The text was updated successfully, but these errors were encountered: