thys/CountSnoc.thy
author fahadausaf <fahad.ausaf@icloud.com>
Tue, 07 Oct 2014 12:33:27 +0100
changeset 22 fff2b8d356a5
child 23 768851ac930b
permissions -rw-r--r--
Count

theory CountSnoc
imports Main
begin


datatype 'a myList = Nil | Cons 'a "'a myList"

fun app_list :: "'a myList \<Rightarrow> 'a myList \<Rightarrow> 'a myList" where
"app_list Nil ys = ys" |
"app_list (Cons x xs) ys = Cons x (app_list xs ys)"

fun rev_list :: "'a myList \<Rightarrow> 'a myList" where
"rev_list Nil = Nil" |
"rev_list (Cons x xs) = app_list (rev_list xs) (Cons x Nil)"

fun count_list :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where
"count_list x [] = 0" |
"count_list x (y#xs) = (
  if x = y then Suc(count_list x xs) 
  else count_list x xs)"

value "count_list 2 [1,2,1,1]"