Unification / logical error of type Isabelle

I am just starting to work at Isabelle, and I get a type unification error when working through Exercise 3.3 in Concrete Semantics :

Define a lookup function

subst :: vname β‡’ aexp β‡’ aexp β‡’ aexp

such that subst x a eis the result of replacing each occurrence of a variable xwith ain e. For instance:

subst ''x'' (N 3) (Plus (V ''x'') (V ''y'')) = Plus (N 3) (V ''y'')

Here is what I have so far:

theory Scratchpad
imports Main
begin

type_synonym vname = string
type_synonym val = int
type_synonym state = "vname β‡’ val"

datatype aexp = N int | V vname | Plus aexp aexp

fun subst :: "vname β‡’ aexp β‡’ aexp β‡’ aexp" where
"subst x (N a) (N e) = (N e)" |
"subst x (N a) (V e) = (if x=e then (N a) else (V e))" |
"subst x (N a) (Plus e1 e2) = Plus(subst(x (N a) e1) subst(x (N a) e2))"

end

When the third case in the function definition is commented out, running test cases

value "subst ''x'' (N 3) (N 5)"
value "subst ''x'' (N 3) (V ''x'')"

creates (N 5)and (N 3)accordingly, so I know that the first two lines work correctly. Adding the last line results in an error

Type association error: collision of types "_ β‡’ _" and "_ list"

Type error in application: operator is not a function type

: x:: char
: N a:: aexp

, , , (, ). , , x , .

( ), ?

+4
1

: Isabelle/HOL (, ) . , ''abc'' , a, b c ( , ). , , Isar ( ) . , ''...'' , "..." .

. , x (type _ list) ( _ => _). , x ? , ( , , ) . , x (N a) x (N a) ( , f y f y). , . , :

Plus (subst x (N a) e1) (subst x (N a) e2)

subst . ( ;).)

. subst . , subst a (- N). , aexp.

+4

All Articles