Hi, does PolyML support the syntax
<sig> where type t = foo and t' = bar
?
I am getting parse errors at the "and" when I try to use it. OTOH,
<sig> where type t = foo where type t' = bar
parses fine, but my sigs are already verbose enough :(
Hi, does PolyML support the syntax
<sig> where type t = foo and t' = bar
This is not valid signature expression syntax, however the following is.
<sig> where type t = foo and type t' = bar ^^^^
You also have to be careful, because the following is valid (although it is only accepted by MLton and Poly/ML -- the ML Kit, Moscow ML, and SML/NJ reject it).
signature S = sig type t end where type t = int and S' = REAL
The indentation is intended to make clear that "and S' = REAL" is part of the signature binding, not the signature expression, using the productions
<sigdec> ::= signature <sigbind> <sigbind> ::= <sigid> = <sigexp> [and <sigbind>]
This also explains why the "type" above is not redundant.
itz> Hi, does PolyML support the syntax itz> itz> <sig> where type t = foo and t' = bar
Stephen> This is not valid signature expression syntax, however the following Stephen> is.
Stephen> <sig> where type t = foo and type t' = bar Stephen> ^^^^
Stephen> You also have to be careful, because the following is valid (although Stephen> it is only accepted by MLton and Poly/ML -- the ML Kit, Moscow ML, and Stephen> SML/NJ reject it).
Stephen> signature S = Stephen> sig Stephen> type t Stephen> end where type t = int Stephen> and S' = REAL
Stephen> The indentation is intended to make clear that "and S' = REAL" is part Stephen> of the signature binding, not the signature expression, using the Stephen> productions
Stephen> <sigdec> ::= signature <sigbind> Stephen> <sigbind> ::= <sigid> = <sigexp> [and <sigbind>]
OK, but what is the standard (ML97) syntax? I got the syntax above from Larry Paulson's book - I'd assume that it follows the standard (although I wouldn't be _that_ much surprised if it unwittingly endorsed some SMLNJisms).
Stephen> <sigdec> ::= signature <sigbind> Stephen> <sigbind> ::= <sigid> = <sigexp> [and <sigbind>]
OK, but what is the standard (ML97) syntax? I got the syntax above from Larry Paulson's book - I'd assume that it follows the standard (although I wouldn't be _that_ much surprised if it unwittingly endorsed some SMLNJisms).
The above is taken from page 13 of the Definition of SML (Revised), i.e. SML97.
When I said "This is not valid signature expression syntax", I meant according to the SML97 standard.
I hope this clears it up.
On Wednesday, July 3, 2002, at 01:21 , Ian Zimmerman wrote:
itz> Hi, does PolyML support the syntax itz> itz> <sig> where type t = foo and t' = bar
Stephen> This is not valid signature expression syntax, however the following Stephen> is.
Stephen> <sig> where type t = foo and type t' = bar Stephen> ^^^^
OK, but what is the standard (ML97) syntax? I got the syntax above from Larry Paulson's book - I'd assume that it follows the standard (although I wouldn't be _that_ much surprised if it unwittingly endorsed some SMLNJisms).
About a year ago there was a discussion in the SML implementers mailing list about various deviations from Standard ML 97. Andreas Rossberg (I think: I can't find the original message) posted a set of test programs along with the results for various compilers. Poly/ML did pretty well but there were a few cases where it failed to conform. Accepting where type t = foo and t' = bar was one of them. I fixed this in release 4.1.2 so that it conforms to SML 97 and it now insists on the repetition of the word "type".
The repetition of the word "type" seems on the face of it inconsistent with the rest of the language. After all you don't write
type t = int and type s = bool;
as part of a declaration. It does make sense, though, as Stephen pointed out, when you need to disambiguate it from another signature declaration. For example, Poly/ML (4.1.2) rejects the following
signature S = sig type t and s end where type t = int and s = bool;
but the error is not a syntax error, it's
Error: Signature (bool) has not been declared Found near bool
since it is parsing this, correctly, as two signature declarations. Writing a second "type" after the "and"
signature S = sig type t and s end where type t = int and type s = bool;
works. I guess if you're trying to make your code portable across various implementations and various versions the safest way is to repeat the "where type" e.g. signature S = sig type t and s end where type t = int where type s = bool;
David.