From 41cd154483d45c5d2fb0abf392b9bdc63d42b94e Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 25 Jan 2017 15:55:14 -0500 Subject: List.appi --- lib/ur/list.ur | 12 ++++++++++++ lib/ur/list.urs | 3 +++ 2 files changed, 15 insertions(+) (limited to 'lib/ur') diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 50764e46..cc533676 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -311,6 +311,18 @@ fun app [m] (_ : monad m) [a] f = app' end +fun appi [m] (_ : monad m) [a] f = + let + fun app' i ls = + case ls of + [] => return () + | x :: ls => + f i x; + app' (i + 1) ls + in + app' 0 + end + fun mapQuery [tables ::: {{Type}}] [exps ::: {Type}] [t ::: Type] [tables ~ exps] (q : sql_query [] [] tables exps) (f : $(exps ++ map (fn fields :: {Type} => $fields) tables) -> t) = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 432d8c1a..fd56679d 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -65,6 +65,9 @@ val all : a ::: Type -> (a -> bool) -> t a -> bool val app : m ::: (Type -> Type) -> monad m -> a ::: Type -> (a -> m unit) -> t a -> m unit +val appi : m ::: (Type -> Type) -> monad m -> a ::: Type + -> (int -> a -> m unit) -> t a -> m unit + val tabulateM : m ::: (Type -> Type) -> monad m -> a ::: Type -> (int -> m a) -> int -> m (t a) -- cgit v1.2.3 From 59454c9766685b381603aaf116bb43a9515dbdba Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 1 Feb 2017 09:24:17 -0500 Subject: Option.app --- lib/ur/option.ur | 5 +++++ lib/ur/option.urs | 1 + 2 files changed, 6 insertions(+) (limited to 'lib/ur') diff --git a/lib/ur/option.ur b/lib/ur/option.ur index 05c50d1f..baa08466 100644 --- a/lib/ur/option.ur +++ b/lib/ur/option.ur @@ -40,6 +40,11 @@ fun mp [a] [b] f x = None => None | Some y => Some (f y) +fun app [m] [a] (_ : monad m) (f : a -> m {}) x = + case x of + None => return () + | Some y => f y + fun bind [a] [b] f x = case x of None => None diff --git a/lib/ur/option.urs b/lib/ur/option.urs index 126999a3..c30c40e7 100644 --- a/lib/ur/option.urs +++ b/lib/ur/option.urs @@ -9,6 +9,7 @@ val isNone : a ::: Type -> t a -> bool val isSome : a ::: Type -> t a -> bool val mp : a ::: Type -> b ::: Type -> (a -> b) -> t a -> t b +val app : m ::: (Type -> Type) -> a ::: Type -> monad m -> (a -> m {}) -> t a -> m {} val bind : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> t b val get : a ::: Type -> a -> option a -> a -- cgit v1.2.3 From 773c309baa825ae91a9d86358785f8c3056bad8f Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Tue, 21 Feb 2017 16:20:27 +0000 Subject: Button: disabled attribute; allowing number entry using HTML5 widgets --- lib/js/urweb.js | 21 +++++++++++++++++++-- lib/ur/basis.urs | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'lib/ur') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 222a8322..ebe192ca 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -1127,6 +1127,23 @@ function inpt(type, s, name) { return x; } +function inpt_float(type, s, name) { + if (suspendScripts) + return; + + var filterFloat = function(value) { + if (/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/ + .test(value)) + return Number(value); + return null; + } + var x = input(document.createElement("input"), s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }, type, name); + x.value = s.data; + x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, filterFloat(x.value)) }; + + return x; +} + function inp(s, name) { return inpt("text", s, name); @@ -1157,11 +1174,11 @@ function color(s, name) { } function number(s, name) { - return inpt("number", s, name); + return inpt_float("number", s, name); } function range(s, name) { - return inpt("range", s, name); + return inpt_float("range", s, name); } function date(s, name) { diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 23896e27..89a48d59 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -1076,8 +1076,8 @@ val curl : ctext val ctel : ctext val ccolor : ctext -val cnumber : cformTag ([Source = source float, Min = float, Max = float, Step = float, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] -val crange : cformTag ([Source = source float, Min = float, Max = float, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] +val cnumber : cformTag ([Source = source (option float), Min = float, Max = float, Step = float, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] +val crange : cformTag ([Source = source (option float), Min = float, Max = float, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] val cdate : cformTag ([Source = source string, Min = string, Max = string, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] val cdatetime : cformTag ([Source = source string, Min = string, Max = string, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] val cdatetime_local : cformTag ([Source = source string, Min = string, Max = string, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] @@ -1085,7 +1085,7 @@ val cmonth : cformTag ([Source = source string, Min = string, Max = string, Size val cweek : cformTag ([Source = source string, Min = string, Max = string, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] val ctime : cformTag ([Source = source string, Min = string, Max = string, Size = int, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] -val button : cformTag ([Value = string] ++ boxAttrs) [] +val button : cformTag ([Value = string, Disabled = bool] ++ boxAttrs) [] val ccheckbox : cformTag ([Size = int, Source = source bool, Onchange = transaction unit] ++ boxAttrs ++ inputAttrs) [] -- cgit v1.2.3