[Ur] how to use conditions in monads?

Vladimir Shabanov vshabanoff at gmail.com
Mon Sep 5 07:37:54 EDT 2011


2011/9/5 Gergely Buday <gbuday at gmail.com>:
>> stored <- get store;
>> input <- get counter;
>> if (stored <> input)
>>  then set var value
>>  else <nop>
>> sleep 100;
>
> Vladimir wrote:
>
>> Try 'return ()'
>>
>> (if ... then ... else return ()); ...
>
> If I understand correctly, I can use return only at the end of a monad
> chain, can't I?

No. 'return' is not a control structure (not the same 'return' as in C
or Java), it is just a function, and 'return x' is just a monadic
computation which (when performed) returns 'x'.

E.g. you can write
  return 1;
  theTwo <- return "2";
  return three;
  return foo
and it will be just a sequence of computations with final result 'foo'
(and intermediate results thrown away).



More information about the Ur mailing list