-
Notifications
You must be signed in to change notification settings - Fork 73
Newtypes for replace #62
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
Comments
Since these strings aren't typically going to be placed in data structures, maybe |
Isn't that the suggestion though? Requiring newtype wrapping to ensure the strings must be specified in the right order: |
I generally like |
Yeah, but this isn't for documentation purposes, but to remove weird errors and make declarations a bit clearer. And even with assumption that everyone uses right tooling (that's not true of course) editor hints are just recommendations not enfocements. Other approach is something like find :: {hay :: String, needle :: String} -> Maybe String It doesn't introduce new types, but currying is lost. |
Well except records 😄 |
However, I have to say I like the newtype approach (I'm not particularly keen about newtype Pattern = Pattern String
newtype Replacement = Replacement String
replace :: Pattern -> Replacement -> String -> String
replace (Pattern "http") (Replacement "https") "http://example.com" |
If we were to newtype, I prefer @sharkdp's suggestion too - newtyping the first arguments and leaving the last one as a string. |
Agreed, that makes composition nicer too. The other question is whether this is worth a breaking change again, when we haven't finished the 1.0 update cycle yet. (That's part of the reason I suggested using type synonyms to start off with). |
The errors with
replace
where I mix up arguments occur surprisingly often.What do you think, is it worth to add newtype wrappers for replacer/replacee part?
And in general something like
Hay
andNeedle
,SplitBy
and other stuff?The text was updated successfully, but these errors were encountered: