Proposal: Add IsString instance for (Maybe a) to base
Conrad Parker
conrad at metadecks.org
Mon Jul 15 03:40:05 CEST 2013
On 10 July 2013 05:24, Simon Hengel <sol at typeful.net> wrote:
> Hi,
> what about adding
>
> instance IsString a => IsString (Maybe a) where
> fromString = Just . fromString
>
> It makes specifying optional String/Text/... values more convenient.
> Here is an example that uses System.Process.shell:
>
> Use
>
> shell "ls -l" { cwd = "/home/me" }
>
> instead of
>
> shell "ls -l" { cwd = Just "/home/me" }
>
> I'm not yet sure how essential it is. But I somehow can't see any
> issues with it. So why not?
+1
After reviewing the resulting discussion I agree that there's no
possible ambiguity and Simon's use-case is compelling. I think it's
great that this allows us to write obvious code without cluttering the
common use-case with Justs, while still allowing the underlying types
to be properly expressive (ie. admitting a Nothing value when that is
appropriate). This is especially important for a DSL that uses lots of
strings, like shell scripting.
I think (Maybe String) is a perfectly good string; it's just a string
type that has an extra value of Nothing -- and Nothing doesn't even
play a part in the IsString instance.
Conrad.
More information about the Libraries
mailing list