Giter Site home page Giter Site logo

nf's People

Contributors

ezyang avatar treeowl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

treeowl

nf's Issues

Consider adding seriously bogus version

We have

newtype NF a = UnsafeNF a
instance NFData (NF a) where
  rnf x = x `seq` ()

which asserts that NF a is in normal form if it's in WHNF. Sometimes, it's useful to make an even stronger claim.

newtype AlreadyNF a = AlreadyNF a
instance NFData (AlreadyNF a) where
    rnf _ = ()

This asserts that if I have something of type AlreadyNF then it is already in normal form. This offers a way to force the structure of a container without forcing any of its contents:

import Data.Sequence

forceStructure :: Seq a -> ()
forceStructure = rnf . fmap AlreadyNF

Without relying on the fmap/coerce rules in Data.Sequence, this could be written something like

forceStructure = rnf . (coerce :: Seq a -> Seq (AlreadyNF a))

What type role should NF's parameter have?

Currently, we let GHC infer

type role NF representational

I think there's a minor potential problem here. Suppose we have

data T = ...
newtype U = U T

instance NFData T where ...
instance NFData U where ... -- Something *different*

We can coerce from NF T (which is in T-normal form) to NF U (which claims to be in U-normal form). It's not quite clear to me whose problem this is. Should whoever defined U be expected to hide its constructor? Or should we have type role NF nominal?

In practice, I suspect this to come up rather rarely, since types are generally expected to have just one notion of normal form, but there could be exceptions out there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.