Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative pattern matching #2766

Closed
vicuna opened this issue May 21, 2001 · 2 comments
Closed

alternative pattern matching #2766

vicuna opened this issue May 21, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented May 21, 2001

Original bug ID: 363
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi!

I am using OCaml version 3.01 on Windows 2000. We are working on project
using ocaml as a prototyping language. I had a piece of code, very similar
to this:

type expr =
Var of string
| Literal of int
| Plus of (expr * expr)
| Minus of (expr * expr)
| Times of (expr * expr)
| Divide of (expr * expr)

type stmt =
Assign of (expr * expr)
| Return of (expr)

let rec traverseprog_bad = function res -> function
[] -> res
| (s::ss) -> traverseprog_bad (traversestmt_bad res s) ss
and traversestmt_bad = function res -> function
Assign(Var(v1), Var(v2))
| Assign(Var(v1), Plus(Var(v2), Literal()))
| Assign(Var(v1), Plus(Literal(
), Var(v2)))
| Assign(Var(v1), Minus(Var(v2), Literal()))
| Assign(Var(v1), Minus(Literal(
), Var(v2))) ->
((v1, v2)::(v2, v1)::res)
| _ -> res

let rec traverseprog_good = function res -> function
[] -> res
| (s::ss) -> traverseprog_good (traversestmt_good res s) ss
and traversestmt_good = function res -> function
Assign(Var(v1), Var(v2)) ->
((v1, v2)::(v2, v1)::res)
| Assign(Var(v1), Plus(Var(v2), Literal())) ->
((v1, v2)::(v2, v1)::res)
| Assign(Var(v1), Plus(Literal(
), Var(v2))) ->
((v1, v2)::(v2, v1)::res)
| Assign(Var(v1), Minus(Var(v2), Literal())) ->
((v1, v2)::(v2, v1)::res)
| Assign(Var(v1), Minus(Literal(
), Var(v2))) ->
((v1, v2)::(v2, v1)::res)
| _ -> res

let prog = [Assign(Var("a"), Literal(2));
Assign(Var("b"), Literal(3));
Assign(Var("c"), Literal(4));
Assign(Var("d"), Plus(Var("a"), Literal(2)));
Assign(Var("e"), Minus(Literal(10), Var("b")));
Assign(Var("f"), Plus(Var("e"), Var("b")));
Return(Var("f"))]

let res_good = traverseprog_good [] prog
let res_bad = traverseprog_bad [] prog

Actually I tried to use the "_bad" solution first, but I got an Application
Error message box (both in ocaml and ocamlwin) with the following error
message: The instuction at "0x0040ad3c" referenced memory at "0x00000001".
The memory could not be "read".

When I tried the "_good" solution it worked without any problem.

Viktor
This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in error,
please notify the sender immediately and delete the original. Any other
use of the email by you is prohibited.

@vicuna
Copy link
Author

vicuna commented May 21, 2001

Comment author: administrator

Hi!

I am using OCaml version 3.01 on Windows 2000. We are working on project
using ocaml as a prototyping language. I had a piece of code, very similar
to this:

and traversestmt_bad = function res -> function
Assign(Var(v1), Var(v2))
| Assign(Var(v1), Plus(Var(v2), Literal()))
| Assign(Var(v1), Plus(Literal(
), Var(v2)))
| Assign(Var(v1), Minus(Var(v2), Literal()))
| Assign(Var(v1), Minus(Literal(
), Var(v2))) ->
((v1, v2)::(v2, v1)::res)
| _ -> res

Dear OCaml user,

Thank you for your nice bug report.
The bug is known (bug #326 cf http://caml.inria.fr/bin/caml-bugs)
and fixed in the development version.

Basically, using more than one variable in or-parts does not work for
ocamlc/ocaml 3.01 (However it works for ocamlopt).

--Luc Maranget

@vicuna
Copy link
Author

vicuna commented May 21, 2001

Comment author: administrator

Same as bug #326, Luc

@vicuna vicuna closed this as completed Jun 18, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant