summaryrefslogtreecommitdiff
path: root/forum
diff options
context:
space:
mode:
Diffstat (limited to 'forum')
-rw-r--r--forum/author.ur19
-rw-r--r--forum/author.urs19
-rw-r--r--forum/entryClass.ur27
-rw-r--r--forum/entryClass.urs18
-rw-r--r--forum/forum.ur49
-rw-r--r--forum/myOption.ur18
-rw-r--r--forum/myOption.urs18
-rw-r--r--forum/score.ur38
-rw-r--r--forum/score.urs18
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+
(********************************** 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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
+
(********************************** 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 <bbaren@mit.edu>
-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 <http://www.gnu.org/licenses/>. *)
+
+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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
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 (
<xml><p>
{[answer.Body]}
- <span class={entryMetadata}>&mdash;{[answer.Author]} ({[Score.withUnits score "point"]})</span>
+ <span class={entryMetadata}>
+ &mdash;{[answer.Author]} ({[Score.withUnits score "point"]})
+ </span>
</p></xml>));
return (
Template.generic (Some "Forum") <xml>
@@ -126,8 +130,12 @@ and detail (id : int) : transaction page =
</p>
{Author.whenIdentified authorOpt
<xml>
- <form class={voting}><submit action={upvote id} value="⬆" /></form>
- <form class={voting}><submit action={downvote id} value="⬇" /></form>
+ <form class={voting}>
+ <submit action={upvote id} value="⬆" />
+ </form>
+ <form class={voting}>
+ <submit action={downvote id} value="⬇" />
+ </form>
</xml>}
<div>{answerBlock}</div>
@@ -137,7 +145,8 @@ and detail (id : int) : transaction page =
<textarea {#Body} class={entryBody} /><br />
Answering as:
<select {#Author}>
- {Author.whenIdentified' authorOpt (fn u => <xml><option>{[u]}</option></xml>)}
+ {Author.whenIdentified' authorOpt (fn u =>
+ <xml><option>{[u]}</option></xml>)}
<option>Anonymous</option>
</select>
<submit action={reply id} value="Answer" />
@@ -165,14 +174,17 @@ fun prettyPrintQuestion entry : transaction xbody =
<xml><li>
<h3><a link={detail entry.Id}>{[entry.Title]}</a></h3>
{[entry.Body]}
- <span class={entryMetadata}>Asked by {[entry.Author]} ({[Score.withUnits score "point"]})</span>
+ <span class={entryMetadata}>
+ Asked by {[entry.Author]} ({[Score.withUnits score "point"]})
+ </span>
</li></xml>)
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") <xml>
<div class={content}>
@@ -184,11 +196,12 @@ val allQuestions : transaction page =
</xml>)
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") <xml>
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
fun getError [t] maybe =
case maybe of
None => error <xml>Attempted to extract a value out of a None</xml>
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
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 <bbaren@mit.edu>
+
+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 <http://www.gnu.org/licenses/>. *)
+
type score
val insightful : score