thys/CountSnoc.thy
changeset 22 fff2b8d356a5
child 23 768851ac930b
equal deleted inserted replaced
21:893f0314a88b 22:fff2b8d356a5
       
     1 theory CountSnoc
       
     2 imports Main
       
     3 begin
       
     4 
       
     5 
       
     6 datatype 'a myList = Nil | Cons 'a "'a myList"
       
     7 
       
     8 fun app_list :: "'a myList \<Rightarrow> 'a myList \<Rightarrow> 'a myList" where
       
     9 "app_list Nil ys = ys" |
       
    10 "app_list (Cons x xs) ys = Cons x (app_list xs ys)"
       
    11 
       
    12 fun rev_list :: "'a myList \<Rightarrow> 'a myList" where
       
    13 "rev_list Nil = Nil" |
       
    14 "rev_list (Cons x xs) = app_list (rev_list xs) (Cons x Nil)"
       
    15 
       
    16 fun count_list :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where
       
    17 "count_list x [] = 0" |
       
    18 "count_list x (y#xs) = (
       
    19   if x = y then Suc(count_list x xs) 
       
    20   else count_list x xs)"
       
    21 
       
    22 value "count_list 2 [1,2,1,1]"
       
    23  
       
    24 
       
    25 
       
    26 
       
    27