[MLton] Windows ports and paths

Stephen Weeks MLton@mlton.org
Mon, 2 May 2005 14:50:10 -0700


> ... speaking of which:
>             val arcs =
>                case (a1, a2) of
>                   ([], []) => []
>                 | _ =>
>                      (case List.rev a1 of "" :: r => List.rev r | _ => a1) @ a2
> is a rather long way of writing
>             val arcs =
>                (case List.rev a1 of "" :: r => List.rev r | _ => a1) @ a2
> no?

You are right.  Here's an updated definition of concatArcs and concat,
with my latest joinDirFile shown for ease of comparison.

fun concatArcs (a1, a2) =
   let
      val a1 = case List.rev a1 of "" :: r => List.rev r | _ => a1
   in
      a1 @ a2
   end

fun concat (p1, p2) =
   let
      val {arcs = a1, isAbs, vol = v1} = fromString p1
      val {arcs = a2, isAbs = isAbs2, vol = v2} = fromString p2
   in
      if isAbs2 orelse not (volumeMatch (v1, v2))
	 then raise Path
      else toString {arcs = concatArcs (a1, a2), isAbs = isAbs, vol = v1}
   end

fun joinDirFile {dir, file} =
   if dir = "" andalso file = ""
      then ""
   else
      let
	 val {arcs, isAbs, vol} = fromString dir
      in
	 toString {arcs = concatArcs (arcs, [file]),
		   isAbs = isAbs,
		   vol = vol}
      end