From 0156bf0da091dd2a773c08c2917c121bc86643bb Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 19 Aug 2011 15:23:01 -0400 Subject: Basis.mkMonad --- lib/ur/basis.urs | 5 +++++ lib/ur/option.ur | 6 ++++++ lib/ur/option.urs | 2 ++ 3 files changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index ece4bfef..494eaa4b 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -126,6 +126,11 @@ val bind : m ::: (Type -> Type) -> t1 ::: Type -> t2 ::: Type -> m t1 -> (t1 -> m t2) -> m t2 +val mkMonad : m ::: (Type -> Type) + -> {Return : t ::: Type -> t -> m t, + Bind : t1 ::: Type -> t2 ::: Type -> m t1 -> (t1 -> m t2) -> m t2} + -> monad m + con transaction :: Type -> Type val transaction_monad : monad transaction diff --git a/lib/ur/option.ur b/lib/ur/option.ur index 0aa07a2d..5c89fc9d 100644 --- a/lib/ur/option.ur +++ b/lib/ur/option.ur @@ -1,5 +1,11 @@ datatype t = datatype Basis.option +val monad = mkMonad {Return = @@Some, + Bind = fn [a] [b] (m1 : t a) (m2 : a -> t b) => + case m1 of + None => None + | Some v => m2 v} + fun eq [a] (_ : eq a) = mkEq (fn x y => case (x, y) of diff --git a/lib/ur/option.urs b/lib/ur/option.urs index 62687963..ba43613f 100644 --- a/lib/ur/option.urs +++ b/lib/ur/option.urs @@ -1,5 +1,7 @@ datatype t = datatype Basis.option +val monad : monad t + val eq : a ::: Type -> eq a -> eq (t a) val ord : a ::: Type -> ord a -> ord (t a) -- cgit v1.2.3