From 83a790fd621bcdc4a8ecac5db3147b32b11fe61e Mon Sep 17 00:00:00 2001
From: Benjamin Barenblat
Date: Thu, 2 May 2013 22:02:24 -0400
Subject: Forum: Code style and licensing update
---
forum/author.ur | 19 +++++++++++++++++++
forum/author.urs | 19 +++++++++++++++++++
forum/entryClass.ur | 27 +++++++++++++++++++++++----
forum/entryClass.urs | 18 ++++++++++++++++++
forum/forum.ur | 49 +++++++++++++++++++++++++++++++------------------
forum/myOption.ur | 18 ++++++++++++++++++
forum/myOption.urs | 18 ++++++++++++++++++
forum/score.ur | 38 ++++++++++++++++++++++++++++++++++----
forum/score.urs | 18 ++++++++++++++++++
9 files changed, 198 insertions(+), 26 deletions(-)
diff --git a/forum/author.ur b/forum/author.ur
index 5cbc136..6cec6e9 100644
--- a/forum/author.ur
+++ b/forum/author.ur
@@ -1,3 +1,22 @@
+(* Forum.User -- User information
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
+
(********************************** A user ***********************************)
type usernameOrAnonymous = option string
diff --git a/forum/author.urs b/forum/author.urs
index db6e7a8..8b15a23 100644
--- a/forum/author.urs
+++ b/forum/author.urs
@@ -1,3 +1,22 @@
+(* Forum.User -- User information
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
+
(********************************** A user ***********************************)
type usernameOrAnonymous
diff --git a/forum/entryClass.ur b/forum/entryClass.ur
index 26f3c58..059c80c 100644
--- a/forum/entryClass.ur
+++ b/forum/entryClass.ur
@@ -1,9 +1,28 @@
-type entryClass = int
+(* Forum.EntryClass -- Questions, answers, etc.
+Copyright (C) 2013 Benjamin Barenblat
-val eq_entryClass = eq_int
+This file is a part of 6.947.
-val sql_entryClass = sql_prim
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
-val question = 0
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
+type entryClass = int
+val question = 0
val answer = 1
+
+(********************************* Instances *********************************)
+
+val eq_entryClass = eq_int
+
+val sql_entryClass = sql_prim
diff --git a/forum/entryClass.urs b/forum/entryClass.urs
index acd5c79..120d7b5 100644
--- a/forum/entryClass.urs
+++ b/forum/entryClass.urs
@@ -1,3 +1,21 @@
+(* Forum.EntryClass -- Questions, answers, etc.
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
type entryClass
val question : entryClass
diff --git a/forum/forum.ur b/forum/forum.ur
index 23bbbd5..79e110e 100644
--- a/forum/forum.ur
+++ b/forum/forum.ur
@@ -52,7 +52,8 @@ fun queryColumn [tab ::: Name] [field ::: Name] [state ::: Type]
: transaction state =
query q (fn row state => return (f row.tab.field state)) initial
-fun unless [m ::: Type -> Type] (_ : monad m) (cond : bool) (computation : m {}) =
+fun unless [m ::: Type -> Type] (_ : monad m)
+ (cond : bool) (computation : m {}) =
if cond
then return ()
else computation
@@ -70,9 +71,10 @@ fun recordVote (value : Score.score) (entryId : int) _formData : transaction pag
in the first place. *)
let val author = Author.nameError authorOpt
in
- existingVote <- oneOrNoRows1 (SELECT Vote.Value FROM vote
- WHERE Vote.QuestionId = {[entryId]}
- AND Vote.Author = {[author]});
+ existingVote <-
+ oneOrNoRows1 (SELECT Vote.Value FROM vote
+ WHERE Vote.QuestionId = {[entryId]}
+ AND Vote.Author = {[author]});
(* This mimics Reddit's upvote/downvote behavior, which is a bizarrely
complex state machine that is nonetheless totally intuitive, especially
when you're using an AJAXy interface. TODO: Write an AJAXy
@@ -114,7 +116,9 @@ and detail (id : int) : transaction page =
return (
{[entry.Body]}
- Asked by {[entry.Author]} ({[Score.withUnits score "point"]})
+
+ Asked by {[entry.Author]} ({[Score.withUnits score "point"]})
+
)
val allQuestions : transaction page =
- questionsList <- queryX1' (SELECT * FROM entry
- WHERE Entry.Class = {[EntryClass.question]}
- ORDER BY Entry.Id DESC)
- prettyPrintQuestion;
+ questionsList <-
+ queryX1' (SELECT * FROM entry
+ WHERE Entry.Class = {[EntryClass.question]}
+ ORDER BY Entry.Id DESC)
+ prettyPrintQuestion;
return (
Template.generic (Some "Forum – All questions")
@@ -184,11 +196,12 @@ val allQuestions : transaction page =
)
fun main () : transaction page =
- newestQuestions <- queryX1' (SELECT * FROM entry
- WHERE Entry.Class = {[EntryClass.question]}
- ORDER BY Entry.Id DESC
- LIMIT 5)
- prettyPrintQuestion;
+ newestQuestions <-
+ queryX1' (SELECT * FROM entry
+ WHERE Entry.Class = {[EntryClass.question]}
+ ORDER BY Entry.Id DESC
+ LIMIT 5)
+ prettyPrintQuestion;
askerOpt <- Author.current;
return (
Template.generic (Some "Forum")
diff --git a/forum/myOption.ur b/forum/myOption.ur
index e859454..eaa4599 100644
--- a/forum/myOption.ur
+++ b/forum/myOption.ur
@@ -1,3 +1,21 @@
+(* Forum.MyOption -- Extensions for the Option module
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
fun getError [t] maybe =
case maybe of
None => error Attempted to extract a value out of a None
diff --git a/forum/myOption.urs b/forum/myOption.urs
index 890c31b..e9aa90b 100644
--- a/forum/myOption.urs
+++ b/forum/myOption.urs
@@ -1 +1,19 @@
+(* Forum.MyOption -- Extensions for the Option module
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
val getError : t ::: Type -> option t -> t
diff --git a/forum/score.ur b/forum/score.ur
index a966a4d..217c308 100644
--- a/forum/score.ur
+++ b/forum/score.ur
@@ -1,6 +1,29 @@
+(* Forum.Score -- Upvotes and downvotes
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
type score = int
-val update = plus
+val insightful = 1
+val undecided = 0
+val inane = -1
+
+
+(********************************* Instances *********************************)
val eq_score = eq_int
@@ -10,12 +33,19 @@ val sql_score = sql_prim
val sql_summable_score = sql_summable_int
val nullify_score = @@nullify_prim [int] sql_int
-val insightful = 1
-val undecided = 0
-val inane = -1
+
+(********************************* Updating **********************************)
+
+val update = plus
+
+
+(******************************** Conversion *********************************)
fun toInt s = s
+
+(****************************** Pretty-printing ******************************)
+
fun withUnits s base =
show s ^ " " ^ (case s of
1 => base
diff --git a/forum/score.urs b/forum/score.urs
index 616d1b6..5e179f2 100644
--- a/forum/score.urs
+++ b/forum/score.urs
@@ -1,3 +1,21 @@
+(* Forum.Score -- Upvotes and downvotes
+Copyright (C) 2013 Benjamin Barenblat
+
+This file is a part of 6.947.
+
+6.947 is is free software: you can redistribute it and/or modify it under the
+terms of the GNU Affero General Public License as published by the Free
+Software Foundation, either version 3 of the License, or (at your option) any
+later version.
+
+6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with 6.947. If not, see . *)
+
type score
val insightful : score
--
cgit v1.2.3