Re: Removing MonadFail from Monad

Hey Andreas, 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.
- 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? Greetings, David/quchen

* David Luposchainsky
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?
One notable case of one-constructor types defined not via data is tuples. You certainly don't want warnings for that! Regarding newtypes vs data, I'm not so sure it should make a difference. It's customary to make one-field types newtypes, and then, if one realizes that more fields are needed, turn them into proper data types. Roman

On 17.12.2013 00:32, Roman Cheplyaka wrote:
* David Luposchainsky
[2013-12-16 23:57:19+0100] 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?
One notable case of one-constructor types defined not via data is tuples. You certainly don't want warnings for that!
Should not tuple types be understood as data (,) a b = (,) a b data (,,) a b c = (,,) a b c making them one-constructor types?!
Regarding newtypes vs data, I'm not so sure it should make a difference. It's customary to make one-field types newtypes, and then, if one realizes that more fields are needed, turn them into proper data types.
I agree. What operational semantics is concerned (this mean the execution model of Haskell in the programmer's mind), newtype = data Cheers, Andreas -- Andreas Abel <>< Du bist der geliebte Mensch.

* Andreas Abel
On 17.12.2013 00:32, Roman Cheplyaka wrote:
* David Luposchainsky
[2013-12-16 23:57:19+0100] 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?
One notable case of one-constructor types defined not via data is tuples. You certainly don't want warnings for that!
Should not tuple types be understood as
data (,) a b = (,) a b data (,,) a b c = (,,) a b c
making them one-constructor types?!
You may think of it this way. But for the purposes of this proposal, tuples shouldn't be treated like data types, because there's no possibility they will every be extended with more constructors.
Regarding newtypes vs data, I'm not so sure it should make a difference. It's customary to make one-field types newtypes, and then, if one realizes that more fields are needed, turn them into proper data types.
I agree. What operational semantics is concerned (this mean the execution model of Haskell in the programmer's mind),
newtype = data
Not really. There's a semantic difference (both in operational and denotational semantics) — see http://www.haskell.org/haskellwiki/Newtype Not that this is relevant for this discussion. Roman

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.
participants (3)
-
Andreas Abel
-
David Luposchainsky
-
Roman Cheplyaka