I've been trying to create a function with a tuple-list as an argument but I keep getting the error: "unresolved flex record (need to know the names of ALL the fields in this context)" My code is:
fun convert d = ( (map (#1) d) , (map (#2) d) );
This is basicaly trying to convert a list of pairs into a pair of lists.I've also tried to declare the type of d
as :('a * 'b) list
but that resulted in even more errors.
I assume that this has something to do with the unknown size of the tupple and could use some help on how to make it known.
I suspect that the issue you ran into with annotating the type of
d
was actually just that you weren't surrounding the annotation with parens, this works for me:However, this isn't great SML style. Using
#1
,#2
,#n
and so on is somewhat discouraged since it leads to issues like this, where you've lost some of the usual succintness that type inference gives you.Instead, you can define some explicit selection functions for pairs:
(Note that I've also dropped some superfluous parenthesis from the body of
convert
, since function application has higher precedence then tuple construction, and I've also dropped the semi-colon which is only really necessary when sequencing imperative code or when typing code into the REPL)This is a pretty good style guide for Standard ML, from a course at Harvard (or maybe Tufts). An older version of that doc mentioned this specifically under "Common mistakes to avoid".