[MLton-user] StringCvt.cs int'ness is not visible.

Matthew Fluet fluet@cs.cornell.edu
Tue, 2 Nov 2004 21:25:24 -0500 (EST)


> fun test n = let val matches = StringCvt.scanString (BT.find cregex)
> line
>                  val tree = Option.valOf matches
>              in
>                  case MatchTree.nth(tree,n) of
>                      NONE => "0"
>                    | SOME {len,pos} => Int.toString (pos) (* or
> String.substring (line,pos,len)*)
>              end
>
> end

You have your scan inverted.  Try the following:

fun test n =
   let
      val matches = (BT.find cregex) Substring.getc (Substring.full line)
      val (tree,rest) = Option.valOf matches
   in
      case MatchTree.nth(tree,n) of
	 NONE => "0"
       | SOME {len,pos} => Substring.string (Substring.slice(pos,0,SOME len))
   end

end

I don't know the SML/NJ RegExp library, but from the description of
REGEXP.find, it appears that pos will hold the substring where the regexp
match starts, and len will hold the length of the match.  The code above
prints out the match.

> This works in SML/NJ and fails to compile in MLTON.
> It appears that the StringCvt.cs int'ness is hidden.

SML/NJ does not conform to the Basis Library specification. The
StringCvt.cs type is abstract.

> I am not saying this is a proper solution, just a solution.
> But it does seem that unless one can see StringCvt.cs as an int (which
> is how its defined in the StringCvt structure), then it is a bit
> useless.

See the discussion at the bottom of:
  http://www.standardml.org/Basis/string-cvt.html