racket-algebraic icon indicating copy to clipboard operation
racket-algebraic copied to clipboard

Matching in required structs

Open gpoesia opened this issue 3 years ago • 3 comments

Hi,

I'm new to Racket, so this is likely my mistake. But is it a known limitation that function can't deconstruct structs that come from another file?

Here's a minimal example to illustrate.

If we have a single file:

#lang algebraic/racket/base

(struct S (a))

(define f
  (function
    [(S a) a]
    [_ 0]))

(printf "= ~a\n" (f (S 1)))

It prints 1, as desired. But now, if we move the declaration of S to another file, and require it from this one, then it prints 0 (doesn't match anymore).

If it is a known limitation, is there a way around it?

gpoesia avatar Oct 06 '20 20:10 gpoesia

Hi Gabriel,

This is a new one. Thanks for reporting it.

Work on Algebraic Racket stopped abruptly about a year ago, upon discovering other cross-module scoping bugs I didn't know how to fix, but I should know how to fix them all now. I'll take a closer look over the weekend and probably just rewrite everything to respect module boundaries.

Cross-module scoping is the steepest part of the Racket learning curve, in my experience. If you're at a similar point in your Racket journey, I'd be happy to discuss the underlying issues with you in greater detail.

Eric

On Tue, Oct 6, 2020 at 4:29 PM Gabriel Poesia [email protected] wrote:

Hi,

I'm new to Racket, so this is likely my mistake. But is it a known limitation that function can't deconstruct structs that come from another file?

Here's a minimal example to illustrate.

If we have a single file:

#lang algebraic/racket/base

(struct S (a))

(define f (function [(S a) a] [_ 0]))

(printf "= ~a\n" (f (S 1)))

It prints 1, as desired. But now, if we move the declaration of S to another file, and require it from this one, then it prints 0 (doesn't match anymore).

If it is a known limitation, is there a way around it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dedbox/racket-algebraic/issues/91, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD35UP2QPELJW62UVRCTSTSJN43JANCNFSM4SGQP6MA .

dedbox avatar Oct 07 '20 18:10 dedbox

Hi Eric,

That would be awesome! Thank you for all your work in Algebraic Racket - I'm having a lot of fun with it and Racket in general, recently.

I think I'm still quite behind in my Racket journey, but I'd love to understand in more detail. I tried a little bit to use DrRacket's macro stepper to see which primitives you used in the matching code and try to understand what changes between modules, but I didn't go very far. If you have pointers, I'm curious to know more.

Thanks again,

Gabriel

gpoesia avatar Oct 07 '20 21:10 gpoesia

There's been a snag. I can't reproduce the bug on my end. Fortunately, the package needs an overhaul anyway, to ensure these sorts of issues have been dealt with cleanly. I'll do my best to narrate what I find, why they're problematic w.r.t. to scoping issues, and how things change to deal with it.

In case you'd like to follow along, I'll keep a clean and granular commit log on the better-hygiene branch and use the discussion here to track interesting changes.

At this point, better-hygiene is even with master.

dedbox avatar Oct 13 '20 17:10 dedbox