Monday, 15 April 2013

ml - SML doesn't acknowledge ord or chr -



ml - SML doesn't acknowledge ord or chr -

i'm using illustration "gentle intro ml"

fun incfirst s = chr(ord s + 1) ^ substring(s, 1, size s -1);

but "standard ml of new bailiwick of jersey v110.76 [built: tue oct 22 14:04:11 2013]" doesn't it.

error: operator , operand don't agree [tycon mismatch]

i can't this:

> ord "c";

without getting error

error: operator , operand don't agree [tycon mismatch]

it doesn't recognize

load "char";

either. doing wrong?

you need ord #"c" because "c" string , #"c" character.

your function has 2 problems:

trying glue character , string using ^, operates on strings trying utilize ord on string

an ugly solution this:

fun incfirst s = char.tostring(chr(ord(string.sub(s,0)) + 1)) ^ substring(s, 1, size s -1);

i think create prettier solution using explode , implode , let block pattern match don't remember plenty sml syntax off top of head it.

ml

No comments:

Post a Comment