I have this from The Little MLer
datatype 'a pizza =
Bottom
| Topping of ('a * ('a pizza))
and this
datatype fish =
Anchovy
| Lox
| Tuna
and this working code
fun rem_fish (f, fp) =
let
fun eq_fish (Anchovy,Anchovy) = true
| eq_fish (Lox,Lox) = true
| eq_fish (Tuna,Tuna) = true
| eq_fish (_,_) = false
in
case fp of
Bottom => Bottom
| Topping(x,y) =>
case eq_fish (f,x) of
true => rem_fish (f,y)
| false => Topping (x,rem_fish (f,y))
end
which will take a fish type and a fish pizza pair and remove that particular fish in the first argument
- rem_fish (Tuna, Topping (Tuna, (Topping (Anchovy, Topping (Lox, Topping (Tuna, Bottom))))));
Topping (Anchovy,Topping (Lox,Bottom)) : fish pizza
Good, so I then see this code (which I've changed to be case
based) marked as "ungrammatical"
fun rem_fish (f, fp) =
case fp of
Bottom => Bottom
| Topping (f,fp') => rem_fish (f,fp')
| Topping (x,fp') => Topping (x,rem_fish (f,fp'))
but this error
Error: match redundant
: Bottom => ...
: Topping (f,fp') => ...
: --> Topping (x,fp') => ...
What does this error mean? What's wrong with the code? The last line could have been something like this
Topping (_,fp') => Topping (?,rem_fish (f,fp'))
but then I don't know what ?
could have been.