Skip to content

make match safe#14

Merged
garyb merged 1 commit into
purescript:masterfrom
davidchambers:match
Nov 4, 2014
Merged

make match safe#14
garyb merged 1 commit into
purescript:masterfrom
davidchambers:match

Conversation

@davidchambers
Copy link
Copy Markdown
Contributor

String.prototype.match returns null if there is no match. For example:

> 'abc'.match(/x/)
null

This change is largely copied from #13.

Comment thread src/Data/String/Regex.purs Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type seems incorrect. Something like

forall r. Fn4 Regex String ([String] -> r) r r

makes more sense to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the lines I copied without fully understanding. I'll update the type now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Could you explain ([String] -> r)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type r in our case is Maybe [String], so Just and Nothing have type [String] -> Maybe [String] and Maybe [String] respectively. But looking at the code, there is nothing which uses the fact that the result is of type Maybe [String], all we care about is that

  • Just(m) and Nothing have the same type.
  • Just takes an argument of type [String]

so we can generalize the result type from Maybe [String] to r for all r.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terrific explanation! Thank you, @paf31.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Nov 3, 2014

Looks good, thanks. I put one comment on the code itself, though.

garyb added a commit that referenced this pull request Nov 4, 2014
@garyb garyb merged commit 4e7f0d5 into purescript:master Nov 4, 2014
@garyb
Copy link
Copy Markdown
Member

garyb commented Nov 4, 2014

Thanks 👍

Before making a release for this I'll check that there's nothing else that needs making safe, as this should be a new v0.x.0 release given that it breaks the API yet again!

@davidchambers davidchambers deleted the match branch November 4, 2014 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants