'a list"...">

Function double list in Isabelle

I would like to define a function in Isabelle / HOL that doubles the list

fun double :: "'a list => 'a list" where
...

such that double [x1, x2, ...] = [x1, x1, x2, x2, ...]

I tried the following:

fun double :: " 'a list ⇒ 'a list" where
"double [] = []" |
"double [x#[l]] = x # x # double [l]"

as well as some other definitions. I get an error

Type Association Error

Application type error: incompatible operand type

What is wrong with my function?

+1
source share
1 answer

In fact, the error message contains additional information. Namely

Operator:  double :: 'a list ⇒ 'a list
Operand:   [[x, l]] :: ??'a list list

which tells us what [[x, l]]type is ?'a list list, i.e. list of lists. Since you want to pass it as an argument doublethat expects a type argument 'a list, you will get a type error.

[[x, l]]

`double [x # [l]]`

x#[l] [x, l].

. , ( , ;)) Isabelle [, ] . .

fun double :: " 'a list ⇒ 'a list"
where
  "double [] = []" |
  "double (x#xs) = x # x # double xs"
+3

All Articles