Visitar URL original
Add deeply strict liftM · Issue #13 · haskell/deepseq · GitHub
Skip to content

Add deeply strict liftM #13

Closed
Closed

Description

@treeowl

Control.Monad offers <$!>. By analogy, I believe this package should offer

(<$!!>) :: (Monad m, NFData b) => (a -> b) -> m a -> m b
f <$!!> m = m >>= \x -> return $!! f x

Activity

  1. RyanGlScott commented on Aug 15, 2016

    @RyanGlScott
    Member

    Sanity-check: is this quite analogous to (<$!>) from base? Its definition is:

    (<$!>) :: Monad m => (a -> b) -> m a -> m b
    f <$!> m = do
      x <- m
      let z = f x
      z `seq` return z

    Whereas with (<$!!>), we have something that's closer to:

    (<$!!>) :: (Monad m, NFData b) => (a -> b) -> m a -> m b
    f <$!!> m = do
      x <- m
      f x `deepseq` return (f x)

    I'd hope that GHC is smart enough to apply CSE on the two occurrences of f x, but maybe it'd be wise to use explicit sharing here.

  2. treeowl commented on Aug 15, 2016

    @treeowl
    ContributorAuthor

    I don't understand how it could translate the way you say. Doesn't $!! take care of the sharing here? If not, that's broken.

  3. treeowl commented on Aug 15, 2016

    @treeowl
    ContributorAuthor

    Actually, $!! shouldn't have to worry about it either. Unless GHC actually copies the expression for no reason, we should be fine.

  4. RyanGlScott commented on Aug 15, 2016

    @RyanGlScott
    Member

    Ah, you're right, I inlined one too many definitions in my head. The fact that you're using ($!!) here explicitly takes care of that issue. Carry on :)

  5. treeowl commented on Aug 15, 2016

    @treeowl
    ContributorAuthor

    The bigger problem is that <$!> is weird. It should really be called <!$>. <$!> should force the argument; <!$!> should force both. For deepseq, I think only <!!$> and <$!!> are really useful. But it's too late to fix this, so we should follow base for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions