arliss_obsidian/fp/Language/Expressions/Lambda Functions.md

23 lines
425 B
Markdown
Raw Normal View History

2024-09-24 22:52:08 +00:00
lambda functions are anonymous functions (as opposed to [[Functions|top-level functions]]) that can be written anywhere:
```haskell
\ <params> -> <body>
```
```haskell
prependHello a = "hello, " <> a
appendName = \a -> a <> "henry!"
str = appendName $ prependHello ""
-- hello, henry!
```
their parameters can destructure their arguments:
```haskell
let
getFoo = \{foo} -> foo
in
getFoo {foo: "hello"}
-- "hello"
```