if (p:string list) = c (is the only element)
Posted on In QAif (p:string list) = [c] then (divide p1 c)
showing unbound value c.
i want to equalise (if one element in p which is (c:anything)) and use that variable
let p = ["ocaml"]
let f s = match s with
| [c] -> print_endline c
| _ -> print_endline "ops"
f p
It will print:
ocaml
If you like Scala:
scala> def f(s: List[String]): Unit = {
| s match {
| case List(c) => print(c)
| case _ => print("ops")
| }
| }
f: (s: List[String])Unit
scala> val p = List("Scala")
p: List[java.lang.String] = List(Scala)
scala> f(p)
Scala