Frage

I have made the function fun charListToInt (y) = map (fn x => Char.ord (x) - 64) y::[] that takes a char list and returns a int list list with the integer code of the character (A = 1, B = 2, C = 3...).

For example: charListToInt [#"A", #"B", #"C", #"D", #"E"] = [[1, 2, 3, 4, 5]].

What I really want to do is to give the function the type val charListToInt = fn : char list list -> int list list instead of just having char list as input, like this:

[[#"A", #"B"], [#"C", #"D"]] = [[1, 2], [3, 4]]

Can this really be done by using the map-function?

War es hilfreich?

Lösung

val charListListToIntListList = map (map (fn c => ord c - ord #"A" + 1))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top