[Haskell-cafe] Implicit Multi Threading in Switch Case

Clinton Mead clintonmead at gmail.com
Tue Jun 20 11:18:55 UTC 2017


I don't think you're going to be able to achieve this with pattern matches.

What may be useful is some of the stuff in the package unamb
<https://hackage.haskell.org/package/unamb-0.2.5>.

On Tue, Jun 20, 2017 at 8:10 PM, Isaac Elliott <isaace71295 at gmail.com>
wrote:

> Hey Yotam,
>
> Pattern matching clauses evaluate from left to right. You can get the
> behavour you're after by swapping the arguments in the tuple:
>
> case (stop, infi) of
>   (Just _, Nothing) -> 1
>   (_, _) -> 2
>
> Evaluates to 2
>
> On Tue, 20 Jun. 2017, 7:29 pm Yotam Ohad, <yotam2206 at gmail.com> wrote:
>
>> Hi,
>> After reading "Push-Pull Functional Reactive Programming
>> <https://pdfs.semanticscholar.org/fb7a/879d639641341e025197b40afad9e21f0ce5.pdf>"
>> I had an idea about deciding which, of two events, comes first. Instead of
>> using forkIO, I tried something like the following:
>>
>> infi :: Maybe Int
>> infi = infi
>>
>> stop :: Maybe Int
>> stop = Nothing
>>
>> test :: Int
>> test = case (infi, stop) of
>>     (Nothing, Just _) -> 1
>>     (_, _) -> 2
>>
>> Here, infi is an action that never ends, and stop a function that ends
>> immediately. I thought that the compiler would see that stop evaluates
>> immediately to Nothing and thus will return 2, but it tries to evaluate
>> infi and get stuck.
>>
>> I think it happens because I am using a tuple to hold both values (but
>> not really sure about it). Do you know a way to make this arrangement work?
>>
>> Yotam
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170620/8b432c3f/attachment.html>


More information about the Haskell-Cafe mailing list