Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

syntax - Type int vs. [int ty] in sml

My problem seems simple enough but I can't seem to find an answer anywhere. I'm not sure what the difference is between types int and [int ty] in sml. I'm getting a [tycon mismatch] error when trying to use a list of int tuples as input for my function. For example:

input: number_in_month ((1993, 2, 2), (1776, 7 4), (1994, 7, 5)) 7;

Error: operator and operand don't agree [tycon mistmatch]
operator domain: (int * int * int) list * int
operand:         ([int ty] * [int ty] * [int ty]) *
                 ([int ty] * [int ty] * [int ty]) *
                 ([int ty] * [int ty] * [int ty])

I've tried several ways to enclose my input paren-wise, but nothing seems to change the result.

question from:https://stackoverflow.com/questions/65854907/type-int-vs-int-ty-in-sml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SML/NJ (which this looks like an error message from) uses [int ty] (in diagnostics) to denote the set of integral types corresponding to the overloading class Int. You can take a look at Appendix E of the revised definition ('97) of SML for more information, but this isn't really related to your issue.

If you look carefully you can see that the domain of number_in_month is (int * int * int) list * int, yet you provide it a triple of int triples---this ought to be a list of int triples instead. Moreover you attempt to pass another argument in a curried fashion, but we can see it ought to be in a tuple with this list instead based on this error.

Correspondingly you'd likely want

number_in_month ([(1993, 2, 2), (1776, 7 4), (1994, 7, 5)], 7)

instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...