fram-lang/dbl

Pattern matching with literals

Open

#137 opened on Jun 20, 2024

View on GitHub
 (1 comment) (0 reactions) (1 assignee)OCaml (28 forks)auto 404
2.1. pattern-matchinggood first issue

Repository metrics

Stars
 (46 stars)
PR merge metrics
 (PR metrics pending)

Description

During the coding of the Hood-Melville queue, I encountered an error message when I had put in a pattern matching an exact value of one of the parameters. Simplifying the issue:

  1. For this interpreter gives error:
data NoneNegativeInt = NNInt of Int

let subOne value = 
match value with
| NNInt 0 => NNInt 0
| NNInt n => NNInt (n-1)
end
  1. For this interpreter doesn't give error:
data NoneNegativeInt = Zero | NNInt of Int

let subOne value = 
match value with
| Zero => Zero
| NNInt n => if n == 1 then Zero else NNInt (n - 1)
end

I think it would be great to be able to write matches like in the first point.

Contributor guide