[Haskell-cafe] Does Haskell have this SML syntax?

Ignat Insarov kindaro at gmail.com
Fri Mar 26 05:10:07 UTC 2021


Hello Galaxy Being!

You can do this:

    module Y where

    substitute ∷ (α → Bool) → (α, [α]) → [α]
    substitute predicate = \ thing → case thing of
      (_, [ ]) → [ ]
      (substitution, (x: xs)) →
        let remainder = substitute predicate (substitution, xs) in
          if predicate x
          then substitution: remainder
          else x: remainder

It is even nicer since we can factor out the common part of the `if`
block into a `let … in`. You can also enable the `LambdaCase` language
extension and it will let you elide the `thing` thing.

I am not sure if this is what your question is really about… In
principle, of course Haskell has currying. Actually, functions are
usually written in curried form in Haskell. Please let me know if I
missed the substance of your question!


More information about the Haskell-Cafe mailing list