match currently has the following type:
match :: Regex -> String -> Maybe [String]
This is problematic, though, when one considers optional capturing groups:
> 'goodbye'.match(/(good)?bye/)
['goodbye', 'good']
> 'bye'.match(/(good)?bye/)
['bye', undefined]
Perhaps the function's type should be Regex -> String -> Maybe [Maybe String]. This would make the function cumbersome in the case of a pattern with no capturing groups: matching /hello/ would either give Nothing or Just([Just("hello")]).
This is an example of a dynamically typed language allowing a function to do too many things. Now we have the unenviable job of making sense of it all. :)
matchcurrently has the following type:This is problematic, though, when one considers optional capturing groups:
Perhaps the function's type should be
Regex -> String -> Maybe [Maybe String]. This would make the function cumbersome in the case of a pattern with no capturing groups: matching/hello/would either giveNothingorJust([Just("hello")]).This is an example of a dynamically typed language allowing a function to do too many things. Now we have the unenviable job of making sense of it all. :)