Removing MonadFail from Monad
Andreas Abel
andreas.abel at ifi.lmu.de
Tue Dec 17 09:38:48 UTC 2013
On 16.12.2013 23:57, David Luposchainsky wrote:
> On 16.12.2013 23:39, Andreas Abel wrote:
>> "Only one data constructor" should be understood hereditarily; the
>> description is not entirely accurate:
>>
>> -- Only one data constructor: do not add MonadFail constraint
>> do (Only x) <- computation >>> let f (Only x) = more
>> more >>> in computation >>= f
>>
>> (Only x) should be pat such that every constructor in pat is an
>> "only-one" constructor.
>
> Do you mean in case patterns of nested "Only" types appear, like
> `Only (Only' x)`? I hadn't thought of that, good point.
Yes; its easy to give a grammar for "only-one" patterns:
p ::= x (variable)
| C p1 ... pn (C is the only constructor of its data/newtype)
>>> - The case of one data constructor should emit a warning if the data
>>> type is defined via `data`: adding another data constructor can make
>>> patterns in unrelated modules refutable.
>>
>> I don't understand the restriction "is defined via data" since I am not
>> aware of defining constructors outside of data or with something other
>> than the data keyword. Please clarify.
>
> I meant "data and not newtype". If "Only" is a newtype data constructor,
> the pattern is irrefutable by design, is it not?
Of course, I tend to forget about newtype --- in my mind this is just a
data with a single-field single constructor. I never understood why
there is a separate "newtype" syntax when the automatic inference of
"being a newtype" is so trivial. There may be some obscure reason like
relying on a specific internal memory layout of data types in foreign
function interfacing or so...
Cheers,
Andreas
--
Andreas Abel <>< Du bist der geliebte Mensch.
More information about the Libraries
mailing list