In smlnj, how do you convert "string option" to "string"?

Please help, I do not know how the line does this.

Is it possible to convert a string to a string?

+3
source share
3 answers

As already stated, you can use pattern matching to get the desired result. So something like this:

fun foo(NONE) = ""
  | foo(SOME a) = a;

But you could save and use Option.valOfthe SML function instead:

Option.valOf(SOME "my string");(Or just valOf(SOME "my string");as pointed out in the comments of newacct).

+8
source

"option" ML - , , Nullable .NET. None Some of 'a ( 'a option). , 'a, .

, None, . , , None, , .

+3

:

val x = "String";

(* , : *)

val stringfromoptionstring = case x of SOME s = > s                                    | NONE = > "No String found";

0

All Articles