Mila Krumova
Mila Krumova

Reputation: 29

Reflect a tree using sml

The type should be mobile->mobile

where

datatype mobile = Object of int | Wire of mobile * mobile

Code gives me error constructor and argument dont agree in pattern and operator and operand dont agree

fun reflect  (Object v) = Object v
   | reflect (Wire(x,t1,t2)) = Wire(x,reflect t2,reflect t1);

Upvotes: 0

Views: 89

Answers (1)

pad
pad

Reputation: 41290

The error message is very indicative. Wire constructor has 2 arguments while you provide 3 arguments for Wire in reflect function.

A corrected version:

fun reflect (Object v) = Object v
  | reflect (Wire(t1,t2)) = Wire(reflect t2,reflect t1)

Upvotes: 2

Related Questions