Futures in Haskell

后端 未结 3 2109

Does Haskell have an equivalent of Alice\'s ability to bind a variable to a future?

val a = spawn foo;

where foo is some function.

I kn

相关标签:
3条回答
  • 2021-02-07 21:30

    You can use par from Control.Parallel as in

    a `par` f a b c
    where
      a = foo
    

    This is a hint to the runtime that a could be evaluated in another thread.

    0 讨论(0)
  • 2021-02-07 21:33

    Funny, I was just reading a new post by Simon Marlow: Parallel programming in Haskell with explicit futures. Apparently he and others have been working on some new parallel programming abstractions that are intended to be more natural and explicit than the par and pseq APIs.

    0 讨论(0)
  • 2021-02-07 21:38

    Not in the standard library, but

    http://ghcmutterings.wordpress.com/2010/08/20/parallel-programming-in-haskell-with-explicit-futures/

    data Future a = Future a
    
    fork :: Eval a -> Eval (Future a)
    fork a = do a' <- rpar (runEval a); return (Future a')
    
    join :: Future a -> Eval a
    join (Future a) = a `pseq` return a
    
    0 讨论(0)
提交回复
热议问题