[Agda] Some newbie questions

Nils Anders Danielsson nad at Cs.Nott.AC.UK
Fri Nov 21 23:44:55 CET 2008


On 2008-11-21 17:38, Darin Morrison wrote:
> open module M = RawMonad MaybeMonad
> 
> maybeAdd : Maybe ℕ -> Maybe ℕ -> Maybe ℕ
> maybeAdd x y = x >>= \ x' ->
>                y >>= \ y' ->
>                return (x' + y')

Or shorter (without declaring the new module M):

   open RawMonad MaybeMonad

   maybeAdd : Maybe ℕ -> Maybe ℕ -> Maybe ℕ
   maybeAdd x y = x >>= \ x' ->
                  y >>= \ y' ->
                  return (x' + y')

You can also open locally:

   maybeAdd : Maybe ℕ -> Maybe ℕ -> Maybe ℕ
   maybeAdd x y = x >>= \ x' ->
                  y >>= \ y' ->
                  return (x' + y')
     where open RawMonad MaybeMonad

> I'm pretty sure you can't pattern match with lambdas.

Right (except for the absurd patterns () and {}). Hopefully it will be
possible to pattern match on record values in the future.

-- 
/NAD


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.



More information about the Agda mailing list