Comments (3)
Oops now I think I see, notFound is a binding in the match not a matching?
from purescript-jordans-reference.
Correct. notFound
is a binding that binds to the third argument passed to findFirst'
. Since I'm not pattern matching on the value, it can be either Nothing
or Just a
. The example below that section shows that it is initially Nothing
and then becomes Just 1
. Here's another graph reduction if we passed in an empty list:
findFirst Nil (\el -> el == 1)
findFirst' Nil (\el -> el == 1) Nothing
Nothing
And to make things more explicit:
findFirst :: forall a. List a -> (a -> Boolean) -> Maybe a
-- Match 1
findFirst list condition = findFirst' list condition Nothing
findFirst' :: forall a. List a -> (a -> Boolean) -> Maybe a -> Maybe a
-- Match 1
findFirst' Nil condition notFound = notFound
-- Match 2
findFirst' (Cons head tail) condition theA@(Just alreadyFound) =
findFirst' tail condition theA
-- Match 3
findFirst' (Cons head tail) condition Nothing =
let foundOrNot = if (condition head) then (Just head) else Nothing
in findFirst' tail condition foundOrNot
findFirst (Cons 0 (Cons 1 (Cons 2 Nil))) (\el -> el == 1)
-- findFirst - Match 1: match found. Replace args with that match's body
findFirst' (Cons 0 (Cons 1 (Cons 2 Nil))) (\el -> el == 1) Nothing
-- findFirst' - Match 1: match failed. 1st arg was `Cons`, not a `Nil`. Go to next match
-- findFirst' - Match 2: match failed. 3rd arg was `Nothing`, not a `Just`. Go to next match
-- findFirst' - Match 3: match found. Replace args with that match's body.
findFirst' (Cons 1 (Cons 2 Nil)) (\el -> el == 1) Nothing
-- findFirst' - Match 1: match failed. 1st arg was `Cons`, not a `Nil`. Go to next match
-- findFirst' - Match 2: match failed. 3rd arg was `Nothing`, not a `Just`. Go to next match
-- findFirst' - Match 3: match found. Replace args with that match's body.
findFirst' (Cons 2 Nil) (\el -> el == 1) (Just 1)
-- findFirst' - Match 1: match failed. 1st arg was `Cons`, not a `Nil`. Go to next match
-- findFirst' - Match 2: match found. Replace args with that match's body.
findFirst' Nil (\el -> el == 1) (Just 1)
-- findFirst' - Match 1: match found. Replace args with that match's body.
Just 1
from purescript-jordans-reference.
Thanks - I understand it better now, thanks for the detailed response.
from purescript-jordans-reference.
Related Issues (20)
- Link to `purs-backend-es`
- Update GH Actions example CI files
- Type hole usage inside type annotation syntax
- Link to PureScript React post
- Link to 'Case against OOP' article HOT 1
- Link to 'purerl-cookbook' HOT 1
- Link to PS+halogen > TS+React
- From Free to Run - link to 404 HOT 2
- Understanding the Effect Monad. Erroneous example HOT 1
- Link to `PureScript Materials` HOT 1
- Offline version HOT 3
- Link to `fp-ts`' `Migrate from PureScript/Haskell`
- Link to Category Theory Illustrated
- Link to 'Free Boolean Cube'
- Link to `falsify` and other property-based testing links
- Wrongly named variable
- Incorrect instantiation of MonadState for StateT
- Link to 'PureScript for Elm developers'
- Add useful VS Code snippets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-jordans-reference.