Skip to content

add stripPrefix and Pattern for Data.List #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2017
Merged

Conversation

safareli
Copy link
Contributor

@safareli safareli commented Jun 4, 2017

@safareli
Copy link
Contributor Author

safareli commented Jun 4, 2017

if you know a better place in the file for stripPrefix and Pattern let me know


derive instance eqPattern :: (Eq a) => Eq (Pattern a)
derive instance ordPattern :: (Ord a) => Ord (Pattern a)
derive instance newtypePattern :: Newtype (Pattern a) _
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if this instance is correct

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that's how deriving for Newtype works.

stripPrefix (Pattern p') s = tailRecM2 go p' s
where
go prefix input = case prefix, input of
(Cons p ps), (Cons i is) | p == i -> Just $ Loop ({ a: ps, b: is })
Copy link
Contributor

Choose a reason for hiding this comment

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

The parens are redundant in the patterns and in the value here.

-- | A newtype used in cases where there is a list to be matched.
newtype Pattern a = Pattern (List a)

derive instance eqPattern :: (Eq a) => Eq (Pattern a)
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant parens.

@paf31
Copy link
Contributor

paf31 commented Jun 4, 2017

👍 Thanks!

@paf31
Copy link
Contributor

paf31 commented Jun 4, 2017

@garyb Do you want to use the Pattern newtype here too?

This looks good to me.

@garyb
Copy link
Member

garyb commented Jun 4, 2017

The name Pattern is maybe a little strange in the context of lists, but I do think it's better to newtype with something so that the argument order is unambiguous. I can't think of a better name either, so 👍 I guess!

@paf31
Copy link
Contributor

paf31 commented Jun 4, 2017

Prefix?

@garyb
Copy link
Member

garyb commented Jun 4, 2017

That works for sure, but if there's a chance any of the other string-ish functions will be replicated here then Pattern is more widely applicable. Even if just stripSuffix was added. 😉

@paf31
Copy link
Contributor

paf31 commented Jun 4, 2017

True ... ok, merging.

@paf31 paf31 merged commit 79d4cc8 into purescript:master Jun 4, 2017
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