if(p:string list)= c(是唯一元素)

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

如果(p:字符串列表)= [c],则(除以p1 c)
显示未绑定的值c。
我想均衡(如果p中的一个元素是(c:anything))并使用该变量

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

It will print:

它将打印 :

ocaml
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。


If you like Scala:

如果您喜欢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

翻译自: https://www.systutorials.com/if-pstring-list-c-is-the-only-element/

你可能感兴趣的:(if(p:string list)= c(是唯一元素))