[Haskell-cafe] Re: nondet function
Aaron Denney
wnoise at ofb.net
Sun Sep 10 03:00:08 EDT 2006
On 2006-09-10, Ashley Yakeley <ashley at semantic.org> wrote:
> Is it possible to write nondet?
>
> nondet :: a -> a -> a
>
> nondet _|_ _|_ = _|_
> nondet _|_ q = q
> nondet p _|_ = p
> nondet p q = p or q
>
> nondet evaluates its arguments in parallel, and returns the first one of
> them to evaluate. It's thus a bit different from the "par" of GPH. This
> isn't referentially transparent, of course, but maybe it could be
> written in the IO monad:
>
> nondet p q = unsafePerformIO (getnondet p q)
>
> getnondet :: a -> a -> IO a
Can you pass p and q to two new threads, have them each force their
argument, and then write it to the same channel? Then read from that
channel once in the original thread.
--
Aaron Denney
-><-
More information about the Haskell-Cafe
mailing list