<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">Can you do:</div><div dir="ltr"><br></div><div dir="ltr">  (f, g) = let f’ = … in (f’, g’)</div><div dir="ltr"><br></div><div dir="ltr">or is a pattern match not allowed at top level?</div><div dir="ltr"><br></div><div dir="ltr">Jeff</div><div dir="ltr"><br><blockquote type="cite">On Nov 22, 2023, at 4:40 PM, Todd Wilson <twilson@csufresno.edu> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">Hello, Cafe:<div><br></div><div>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:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><font face="monospace">fg = let f ... = ... f,g,h ...<br>         g ... = ... f,g,h ...<br>         h ... = ... h ...<br>      in (f,g)<br></font><font face="monospace">f = fst fg<br>g = snd fg<br></font> </blockquote>but is there something more elegant than this that I'm not seeing?<br></div><div><br></div><div>Todd Wilson</div></div>
<span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span>http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></body></html>