[Haskell-cafe] Mutual scoping question
Todd Wilson
twilson at csufresno.edu
Thu Nov 23 01:30:32 UTC 2023
Thanks, Mark. I wanted f and g to be defined at the top level for use
throughout my whole file, rather just inside of a let. Of course, I could
also put the definitions of f, g, and h in their own module/file that hides
the name h and then import this, but I was hoping to have this all in
one place.
--Todd
On Wed, Nov 22, 2023 at 5:26 PM Mark McConnell <mmcconnell17704 at yahoo.com>
wrote:
> What about
>
> let h ... = ... h ...
> in let f ... = ... f,g,h ...
> g ... = ... f,g,h ...
> in ... (main body that uses f and g) ...
>
> This makes the dependencies clear. h stands on its own, f and g use each
> other together with h, and the main body can use f, g, and h.
>
> I believe what you wanted, however, was to express that the main body
> *cannot* (will not, should not) use h. This version does not express that.
> On Wednesday, November 22, 2023 at 07:40:25 PM EST, Todd Wilson <
> twilson at csufresno.edu> wrote:
>
>
> Hello, Cafe:
>
> Is there a preferred way to define two top-level mutually recursive
> functions, f and g, that both use a common local function h such that h is
> (1) only defined once and (2) does not escape the scope of f and g? I
> suppose it could be done like this:
>
> fg = let f ... = ... f,g,h ...
> g ... = ... f,g,h ...
> h ... = ... h ...
> in (f,g)
> f = fst fg
> g = snd fg
>
>
> but is there something more elegant than this that I'm not seeing?
>
> Todd Wilson
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20231122/9cd650a7/attachment.html>
More information about the Haskell-Cafe
mailing list