[Haskell-cafe] Mutual scoping question

Daniel Casanueva daniel.casanueva at proton.me
Tue Nov 28 08:40:44 UTC 2023


I hope I am not misunderstanding the question, but if you want to define f, g and h, but only export f and g, this is what you would do in Haskell:

module Foo.Bar (f, g) where

f = ...
g = ...
h = ...

The module header determines what gets exported.

On Tuesday, November 28th, 2023 at 07:35, Richard O'Keefe <raoknz at gmail.com> wrote:


> 
> 
> SML has
> local
> declarations
> in
> declarations
> end
> and there is no fundamental reason why Haskell couldn't.
> Is there some reason why you cannot put f g and h in a module and just
> export f and g?
> 
> On Thu, 23 Nov 2023 at 16:42, Todd Wilson twilson at csufresno.edu wrote:
> 
> > It seems (surprisingly to me) that such pattern matches are allowed at the top level, so that would simplify my kludge a bit by skipping the definition of fg. But is using pairs (or the equivalent) in this way the only solution? I was hoping that there might be some kind of top-level definition syntax like
> > 
> > {f .. = ... ; g .. = ...} where h .. = ...
> > 
> > that would correctly capture the scoping I'm looking for.
> > 
> > --Todd
> > 
> > On Wed, Nov 22, 2023 at 5:43 PM Jeff Clites jclites at mac.com wrote:
> > 
> > > Can you do:
> > > 
> > > (f, g) = let f’ = … in (f’, g’)
> > > 
> > > or is a pattern match not allowed at top level?
> > > 
> > > Jeff
> > > 
> > > On Nov 22, 2023, at 4:40 PM, 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.
> > 
> > _______________________________________________
> > 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.
> 
> _______________________________________________
> 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.


More information about the Haskell-Cafe mailing list