if (p:string list) = c (is the only element)

if (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

asked Sep 18, 2014 by Ashok kumar

1 Answer

let p = ["ocaml"]
let f s = match s with
  | [c] -> print_endline c
  | _ -> print_endline "ops"
f p

It will print:

ocaml
answered Sep 30, 2014 by Eric Z Ma (44,280 points)

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
commented Sep 30, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Related questions

1 answer
asked Aug 13, 2013 by anonymous
1 answer
1 answer
1 answer
1 answer
asked Aug 11, 2013 by anonymous
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...