<div dir="ltr">This has been very helpful. I plugged in the version VD above gave and it works. Now, what might be the purpose of this <font face="monospace">\ case</font>? In SML the code I gave simply looks like a trick to simulate a curry where the function takes a parameter, then morphs into a new function that takes the next parameter. What would be the main use of this <font face="monospace">\ case</font> ploy? I can't believe it was dreamt up just to fake currying. What's still strange to me is how the system knows to reach past the <font face="monospace">pred</font><div><br></div><div><font face="monospace">data MyList a = Empty | Cons a (MyList a) deriving (Eq, Ord, Show)</font><br></div><div><font face="monospace">subst_c :: (a -> Bool) -> (a, MyList a) -> MyList a</font><br></div><div><font face="monospace">subst_c pred = \ case<br>                     (_, Empty)    -> Empty<br>                     (n, Cons e t)<br>                       | pred e    -> Cons n $ subst_c pred (n, t)<br>                       | otherwise -> Cons e $ subst_c pred (n, t)</font><br></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">and pattern match on the </font><font face="monospace">(a, MyList a) </font>inside the function. So again, how can it do this and why would I want to?</div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 26, 2021 at 12:37 AM David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Let's start with the basics: lambda expressions.<div dir="auto"><br></div><div dir="auto">ML says</div><div dir="auto"><br></div><div dir="auto">fn x => blah blah</div><div dir="auto"><br></div><div dir="auto">Haskell spells that</div><div dir="auto"><br></div><div dir="auto">\x -> blah blah</div><div dir="auto"><br></div><div dir="auto">Suppose you want to pattern match on the argument. If you only need one pattern, that's cool:</div><div dir="auto"><br></div><div dir="auto">\(x,y) -> blah blah</div><div dir="auto"><br></div><div dir="auto">But what if you need more than one pattern? Well, standard ("Report") Haskell makes you use a case expression:</div><div dir="auto"><br></div><div dir="auto">\mx -> case mx of</div><div dir="auto">    Just x -> blah</div><div dir="auto">    Nothing -> etcetera</div><div dir="auto"><br></div><div dir="auto">But GHC has a widely used language extension to get something more like ML. If you put</div><div dir="auto"><br></div><div dir="auto">-- The "language" is case insensitive.</div><div dir="auto">-- The LambdaCase is case sensitive.</div><div dir="auto">{-# language LambdaCase #-}</div><div dir="auto"><br></div>at the very tippy top of your .hs file, or pass -XLambdaCase to GHCi, then you can write that last one<div dir="auto"><br></div><div dir="auto">\case</div><div dir="auto">    Just x -> blah</div><div dir="auto">    Nothing -> etcetera</div><div dir="auto"><br></div><div dir="auto">There has been some discussion of trying to expand that syntax to support anonymous functions of multiple arguments, but no proposal has been accepted as yet.<br><div dir="auto"><div dir="auto"><br></div><div dir="auto">On Fri, Mar 26, 2021, 1:27 AM Galaxy Being <<a href="mailto:borgauf@gmail.com" rel="noreferrer" target="_blank">borgauf@gmail.com</a>> wrote:<br></div><div dir="auto"><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I'm sure you've answered my question, but I'm too much of a beginner to fathom it. If you could explain, that would be great, but I could also go off and try to grok it myself. Again, thanks.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 26, 2021 at 12:09 AM Ignat Insarov <<a href="mailto:kindaro@gmail.com" rel="noreferrer noreferrer" target="_blank">kindaro@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Galaxy Being!<br>
<br>
You can do this:<br>
<br>
    module Y where<br>
<br>
    substitute ∷ (α → Bool) → (α, [α]) → [α]<br>
    substitute predicate = \ thing → case thing of<br>
      (_, [ ]) → [ ]<br>
      (substitution, (x: xs)) →<br>
        let remainder = substitute predicate (substitution, xs) in<br>
          if predicate x<br>
          then substitution: remainder<br>
          else x: remainder<br>
<br>
It is even nicer since we can factor out the common part of the `if`<br>
block into a `let … in`. You can also enable the `LambdaCase` language<br>
extension and it will let you elide the `thing` thing.<br>
<br>
I am not sure if this is what your question is really about… In<br>
principle, of course Haskell has currying. Actually, functions are<br>
usually written in curried form in Haskell. Please let me know if I<br>
missed the substance of your question!<br>
</blockquote></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div></div></div></div>
</blockquote></div>