Skip to content

Instantly share code, notes, and snippets.

@drostron
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save drostron/a97e659abde1635461a0 to your computer and use it in GitHub Desktop.

Select an option

Save drostron/a97e659abde1635461a0 to your computer and use it in GitHub Desktop.
list value homogeneity
let rec i j = match j with
| [] | [_] -> true
| a :: b :: c -> a = b && i(b::c);;
fun i [] = true
| i [_] = true
| i (a::b::c) = a = b andalso i(b::c);
let i :: (Eq j) => [j] -> Bool
i [] = True
i [_] = True
i (a:b:c) = a == b && i(b:c)
total
i : Eq a => List a -> Bool
i [] = True
i (_::[]) = True
i (a::b::c) = a == b && i(b::c)
@tailrec
def i[T](j: List[T]): Boolean = j match {
case Nil | _ :: Nil ⇒ true
case a :: b :: c ⇒ a == b && i(b::c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment