User:Hkumbum/sandbox

PureScript is a Functional Programming language which compiles to JavaScript. PureScript is a statically typed language and unlike other dynamically typed languages, in PureScript, types exist only at compile time and have no representation at run time. Programs which are correct will be given a type by the compiler, which illustrates its behavior. Conversely, programs which are not given any type are incorrect and will be rejected by the compiler. .One advantage of PureScript over JavaScript is that JavaScript does not support powerful abstractions, as a result it cannot utilize the full capability of functional programming and PureScript addresses this issue by allowing expressive, readable code.

History
Phil Freeman made the first Git commit of PureScript on September 29, 2013. There have been 45 releases with 2924 commits ( as of 15 February, 2016). On Feb 1, 2016, Phil released the latest version v0.8.0 - TIMESLIDES

Getting started
First, setup a working environment for PureScript development.

Following are the tools required: Download the latest version of the PureScript binary from Github and setup the environment variables. Try executing the commands below in command line to verify PureScript installation: Following command is to install the Pulp command line tool. Now you have all tools required to write the first PureScript library.
 * psc - PureScript Compiler
 * npm -Node package Manager
 * pulp- Command line tool

Simple Hello World!

By using pulp init command, create project in an empty directory.

Two directories src, test and a configuration file bower.json are created. src directory contains the source files and test directory contains the tests performed.

Now Modify the src/Main.purs file to create Hello World Program. Now let's build and run the above code.

Features
Below are some of the interesting features of PureScript.

Types and Type Inference
Types in PureScript supports type inference and are not similar to the data types in Java or C#. These types were inspired from ML and Haskell). Following is a simple example code which defines a number (no reference to the Number type anywhere in the code).

Pattern matching
Pattern matching is a technique that allows to code compact functions which express complex ideas. Algebraic data types is a similar feature and is closely related to pattern matching. Below is a Simple Pattern Matching function that calculates GCD of two numbers using Euclidean Algorithm. Pattern matching allows to code simple and declarative cases. Functions work by pairing sets with results. Each line in the function is a case, expressions on left of equals sign are patterns. Each case is evaluated and the first case that matches is returned.

There are various types of patterns like Integer literal, Variable, Wildcard and Boolean literal patterns.

Simple FFI
FFI(Foreign Function Interface) is a feature provided by PureScript that enables communication between PureScript and JavaScript code. FFI is very flexible and it allows developer to choose between using foreign functions or type system. JavaScript functions might return not null values which have to be handled by the developer when designing these interfaces.

Call the GCD PureScript module from JavaScript, using FFI.

Modules
Module keyword is used to refer to modules and all the code in PureScript is written in a module. When a module is imported (using import keyword) aliases are created for all values and types in it. Values, type constructors and data structures can be explicitly imported. Below is an example to import type constructors by passing a list of data constructors in parentheses. Modules can be exported by providing a set of names in parentheses in the declaration similar to import.

Type Classes
Type classes is a powerful kind of abstraction provided by PureScript's type system. Following is the example of show, which is defined by type class in the Prelude module called Show.

Below are some standard type classes defined in the Prelude and Standard libraries.

Eq: Eq type class is used to test two values for equality.

class Eq a where eq :: a -> a -> Boolean

Ord: The Ord type class is used to compare two values for types which support ordering.

data Ordering = LT | EQ | GT class (Eq a) <= Ord a where compare :: a -> a -> Ordering

Num: The Num type class is used to identify the types which support addition, subtraction, multiplication and division operations.

class (DivisionRing a) <= Num a

Do Notation
Do notation is a special syntax which is used to improve the readability of the code. It uses the keyword Do to introduce a block of code which uses do notation. It makes the structure of algorithm clearer. Following is the factors function written using do notation.

factors :: Int -> Array (Array Int) factors n = filter (\xs -> product xs == n) $ do i <- 1 .. n j <- i .. n return [i, j]

Functions and Records
Functions and records are the building blocks of PureScript.

Simple Types
PureScript defines seven built-in types: numbers, strings, booleans, integers, arrays, records, and functions which are defined in Prim module (implicitly imported in every module). These can be seen in PSCi by using the :type command. Following are a few examples.

Unlike JavaScript, all the elements of PureScript array should be of same type.

Records
Records are PureScript's objects and the syntax of Record literals is same as that of JavaScript's Object literals.

Dot is used to access the fields of records.

Functions
Functions can be defined inline ( using \ followed by space) or they can be defined at the top-level of file (by specifying arguments before equal sign).

Version History
Following data is based on the information provided in Github.

Version v0.5.0 - Polymorph
Released on Apr 27, 2014.

Changes: Support for the block has been removed, multiple modules with same name are disallowed, Prelude module is automatically imported.

New features: Multi parameter type-classes, super-classes etc.

Enhancements: Row-type pretty printing was improved, escape check was removed.

Bug Fixes: Overlapping variables in type-class instances are removed, a bug related to in-lining was fixed.

Later versions v0.5.4, v0.5.5, v0.5.6, v0.5.6.1, v0.5.6.2, v0.5.6.3, v0.5.7, v0.5.7.1 have been released with no major changes.

Version v0.6.0 - Holoship
Released on Nov 8, 2014

Changes: Type class hierarchy was refactored, run time type checks has been removed etc.

New features: Newtypes are supported using newtype keyword, multi-line string literals are now supported.

Enhancements: Tail call optimization has been improved. Optimized the saturated calls to data constructors, optimized nested if blocks.

Bug Fixes: Module export related issues have been fixed, binding group calculation issues are fixed etc.

Versions v0.6.0.2, v0.6.1, v0.6.1.1, v0.6.1.2, v0.6.2, v0.6.3, v0.6.4, v0.6.4.1, v0.6.5, v0.6.6, v0.6.7, v0.6.7.1, v0.6.8, v0.6.9.3, v0.6.9.5 have been released later with few changes to v0.6.0

Version v0.7.0 - Meltdown
Released on Jun 29, 2015

Changes: Int and Number literals have been added, Prelude module is no longer imported automatically, FFI JavaScript cannot be provided inline.

Enhancements: Document improvements have been made, computations in Eff monad are now supported in PSCi.

Bug Fixes: Issues with pretty printer have been fixed.

Database Design
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:

The description of the fields of the database for ResponseMap:

1. id: The unique record identifier.

2. reviewed_object_id: The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.

3. reviewer_id: The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.

4. reviewee_id: The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed.

5. type : Indicates the type of the ResponseMap.

6. created_at: The timestamp when the Response was created.

7. updated_at: The timestamp when the Response was updated.

8. calibrate_to: A field of boolean data type.

9. reviwer_is_team: If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.

Models

 * review_response_map.rb
 * participant.rb
 * response_map.rb
 * response.rb
 * assignment_team.rb
 * assignment_participant.rb
 * assignment.rb

Views

 * review_mapping/_review_report.html.erb

Controllers

 * review_mapping_controller.rb
 * participants_controller.rb