
Now that Constraint kinds are pretty much into the mainstream, can we consider the '!' annotation in data declarations as a magic constraint? Not unlike NFData, but only ensuring that said value is in WHNF. So the following definitions would be semantically identical
newtype Foo a = Foo a
data Foo a = Foo !a
data Foo a = (!a) => Foo a
data FooC :: (* -> Constraint) -> * -> * where Foo :: c a => a -> FooC c a type Foo a = FooC ! a
It just occured to me and seemed plausible at first thought, but feel free to flame me because of the magic-ness. Cheers, Gabor

On 04/03/2013 02:06 PM, Gabor Greif wrote:
Now that Constraint kinds are pretty much into the mainstream, can we consider the '!' annotation in data declarations as a magic constraint? Not unlike NFData, but only ensuring that said value is in WHNF.
So the following definitions would be semantically identical
newtype Foo a = Foo a
data Foo a = Foo !a [...]
These two are not identical because f (Foo _) = 3 forces the value if it's 'data' but not if it's 'newtype'. That's irrelevant to your interesting proposal, however. -Isaac

So, what exactly does this constraint mean outside of data declarations?
E.g. how do we interpret
f :: (!a) => a -> a -> a
?
* Gabor Greif
Now that Constraint kinds are pretty much into the mainstream, can we consider the '!' annotation in data declarations as a magic constraint? Not unlike NFData, but only ensuring that said value is in WHNF.
So the following definitions would be semantically identical
newtype Foo a = Foo a
data Foo a = Foo !a
data Foo a = (!a) => Foo a
data FooC :: (* -> Constraint) -> * -> * where Foo :: c a => a -> FooC c a type Foo a = FooC ! a
It just occured to me and seemed plausible at first thought, but feel free to flame me because of the magic-ness.
Cheers,
Gabor
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

Hi Roman, I'd say it would be an empty constraint, since the directory associated with (!) is empty. So this would be trivially satisfied. There is however another possibility, something like `seq`. So both arguments would always be normalized to WHNF before the function f is called. Same for the result. Of course this constraint still would not rule out
f a b = f a b
so no big gain here.
Implementing the latter would be more ambitious, introducing basically
the same sort of 'magic' as with ! on data.
Cheers,
Gabor
On 4/3/13, Roman Cheplyaka
So, what exactly does this constraint mean outside of data declarations?
E.g. how do we interpret
f :: (!a) => a -> a -> a
?
* Gabor Greif
[2013-04-03 20:06:03+0200] Now that Constraint kinds are pretty much into the mainstream, can we consider the '!' annotation in data declarations as a magic constraint? Not unlike NFData, but only ensuring that said value is in WHNF.
So the following definitions would be semantically identical
newtype Foo a = Foo a
data Foo a = Foo !a
data Foo a = (!a) => Foo a
data FooC :: (* -> Constraint) -> * -> * where Foo :: c a => a -> FooC c a type Foo a = FooC ! a
It just occured to me and seemed plausible at first thought, but feel free to flame me because of the magic-ness.
Cheers,
Gabor
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

I don't think so. It's very magic in many ways; more than invoking methods. Eg when pattern matching we know that the thing is evaluated, and so don't need to re-seq it when re-building a similar constructor. And it's not clear what would be gained. A long time ago, seq had this type class Eval a where seq :: a -> b -> b which was a very good, principled thing to do. One of Haskell's few compromises with reality was to make seq polymorphic. Simon | -----Original Message----- | From: ghc-devs-bounces@haskell.org [mailto:ghc-devs-bounces@haskell.org] | On Behalf Of Gabor Greif | Sent: 03 April 2013 19:06 | To: ghc-devs | Subject: [RFC] Bang constraint | | Now that Constraint kinds are pretty much into the mainstream, can we | consider the '!' annotation in data declarations as a magic constraint? | Not unlike NFData, but only ensuring that said value is in WHNF. | | So the following definitions would be semantically identical | | > newtype Foo a = Foo a | | > data Foo a = Foo !a | | > data Foo a = (!a) => Foo a | | > data FooC :: (* -> Constraint) -> * -> * where | > Foo :: c a => a -> FooC c a | > type Foo a = FooC ! a | | It just occured to me and seemed plausible at first thought, but feel | free to flame me because of the magic-ness. | | Cheers, | | Gabor | | _______________________________________________ | ghc-devs mailing list | ghc-devs@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs
participants (4)
-
Gabor Greif
-
Isaac Dupree
-
Roman Cheplyaka
-
Simon Peyton-Jones