<div dir="auto">I don't want to actually put the dictionary there. I want to *pretend* to put the dictionary there. In testing mode, I want to be able to "take one out" by making it out of whole cloth; in production mode I want to just assume there are no bottoms in the constraints and never ever make the dictionaries. But this all is probably better discussed on the existing proposal, now that I know it exists. There are some considerable complications raised there.</div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 21, 2016 11:55 PM, "Edward Kmett" <<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Actually, if you go back to the original form of Seq it would translate to<div><br></div><div><span style="font-size:12.8px">data Seq a => Foo a = Foo !Int !a</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">which requires resurrecting DatatypeContexts, and not</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">data Foo a = Seq a => Foo !Int !a<br><br>The former requires Seq to call the constructor, but doesn't pack the dictionary into the constructor. The latter lets you get the dictionary out when you pattern match on it. meaning it has to carry the dictionary around!</span></div><div><span style="font-size:12.8px"><br>Unfortunately, non-trivial functionality is lost. With the old DatatypeContext translation you can't always unpack and repack a constructor. Whereas with a change to an existential encoding you're carrying around a lot of dictionaries in precisely the structures that least want to carry extra weight.</span></div><div><br></div><div>Both of these options suck relative to the status quo for different reasons.</div><div><br></div><div><span style="font-size:12.8px">-Edward</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 21, 2016 at 2:14 PM, Index Int <span dir="ltr"><<a href="mailto:vlad.z.4096@gmail.com" target="_blank">vlad.z.4096@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There's a related GHC Proposal:<br>
<a href="https://github.com/ghc-proposals/ghc-proposals/pull/27" rel="noreferrer" target="_blank">https://github.com/ghc-proposa<wbr>ls/ghc-proposals/pull/27</a><br>
<div class="m_-393393308368951121HOEnZb"><div class="m_-393393308368951121h5"><br>
On Wed, Dec 21, 2016 at 10:04 PM, David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>> wrote:<br>
> In the Old Days (some time before Haskell 98), `seq` wasn't fully<br>
> polymorphic. It could only be applied to instances of a certain class.<br>
> I don't know the name that class had, but let's say Seq. Apparently,<br>
> some people didn't like that, and now it's gone. I'd love to be able<br>
> to turn on a language extension, use an alternate Prelude, and get it<br>
> back. I'm not ready to put up a full-scale proposal yet; I'm hoping<br>
> some people may have suggestions for details. Some thoughts:<br>
><br>
> 1. Why do you want that crazy thing, David?<br>
><br>
> When implementing general-purpose lazy data structures, a *lot* of<br>
> things need to be done strictly for efficiency. Often, the easiest way<br>
> to do this is using either bang patterns or strict data constructors.<br>
> Care is necessary to only ever force pieces of the data structure, and<br>
> not the polymorphic data a user has stored in it.<br>
><br>
> 2. Why does it need GHC support?<br>
><br>
> It would certainly be possible to write alternative versions of `seq`,<br>
> `$!`, and `evaluate` to use a user-supplied Seq class. It should even<br>
> be possible to deal with strict data constructors by hand or<br>
> (probably) using Template Haskell. For instance,<br>
><br>
> data Foo a = Foo !Int !a<br>
><br>
> would translate to normal GHC Haskell as<br>
><br>
> data Foo a = Seq a => Foo !Int !a<br>
><br>
> But only GHC can extend this to bang patterns, deal with the<br>
> interactions with coercions, and optimize it thoroughly.<br>
><br>
> 3. How does Seq interact with coercions and roles?<br>
><br>
> I believe we'd probably want a special rule that<br>
><br>
> (Seq a, Coercible a b) => Seq b<br>
><br>
> Thanks to this rule, a Seq constraint on a type variable shouldn't<br>
> prevent it from having a representational role.<br>
><br>
> The downside of this rule is that if something *can* be forced, but we<br>
> don't *want* it to be, then we have to hide it a little more carefully<br>
> than we might like. This shouldn't be too hard, however, using a<br>
> newtype defined in a separate module that exports a pattern synonym<br>
> instead of a constructor, to hide the coercibility.<br>
><br>
> 4. Optimize? What?<br>
><br>
> Nobody wants Seq constraints blocking up specialization. Today, a function<br>
><br>
> foo :: (Seq a, Foldable f) => f a -> ()<br>
><br>
> won't specialize to the Foldable instance if the Seq instance is<br>
> unknown. This is lousy. Furthermore, all Seq instances are the same.<br>
> The RTS doesn't actually need a dictionary to force something to WHNF.<br>
> The situation is somewhat similar to that of Coercible, *but more so*.<br>
> Coercible sometimes needs to pass evidence at runtime to maintain type<br>
> safety. But Seq carries no type safety hazard whatsoever--when<br>
> compiling in "production mode", we can just *assume* that Seq evidence<br>
> is valid, and erase it immediately after type checking; the worst<br>
> thing that could possibly happen is that someone will force a function<br>
> and get weird semantics. Further, we should *unconditionally* erase<br>
> Seq evidence from datatypes; this is necessary to maintain<br>
> compatibility with the usual data representations. I don't know if<br>
> this unconditional erasure could cause "laziness safety" issues, but<br>
> the system would be essentially unusable without it.<br>
><br>
> 4. What would the language extension do, exactly?<br>
><br>
> a. Automatically satisfy Seq for data types and families.<br>
> b. Propagate Seq constraints using the usual rules and the special<br>
> Coercible rule.<br>
> c. Modify the translation of strict fields to add Seq constraints as required.<br>
><br>
> David Feuer<br>
> ______________________________<wbr>_________________<br>
> ghc-devs mailing list<br>
> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/ghc-devs</a><br>
______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/ghc-devs</a><br>
</div></div></blockquote></div><br></div>
</blockquote></div></div>