Getting Started Guide - Informatica · Getting Started Guide - Informatica ... - Profiling
Getting Started with PureScript
-
Upload
john-de-goes -
Category
Technology
-
view
1.054 -
download
2
Transcript of Getting Started with PureScript
Getting Started with PureScript
John A. De Goes
Agenda• Introduction
• What is PureScript
• Syntax & Semantics
• Who Uses PureScript
• Why PureScript
• Ecosystem
• Getting Started
• Node.js
• NPM
• Bower
• PureScript
• Pulp
• Hello World
What is PureScript?PureScript is a strongly-typed, purely-functional programming language that compiles to Javascript1, and is written in and inspired by Haskell.
1 And C++!
Syntaximport Control.Applyimport Graphics.Canvas.Freescene = filled $ closed do moveTo 0 0 lineTo 50 0 lineTo 25 50 where closed path = beginPath *> path <* closePath filled shape = shape <* fill
Semantics• Type Inference
• Higher-Kinded Polymorphism
• Support for basic Javascript types
• Extensible records
• Extensible effects
• Optimizer rules for generation of efficient Javascript
• Pattern matching
• Simple FFI
• Modules
• Rank N Types
• Do Notation
• Tail-call elimination
• Type Classes
Who Uses PureScript?2
• SlamData
• Xamarin
• DICOM Grid
• Middlebury Interactive Languages
• DICE.fm
• McGraw Hill Financial
2 Cobbled together from various online sources.*
Why PureScript?Motivation
• You want to or are forced to do front-end or node.js
• You like static typing
• You like functional programming, of the pure variety
• You prefer expressive power over no-frills, opinionated simplicity
• You want to crush Javascript/CoffeeScript/TypeScript/Scala3 beneath your heel... BWAHAHA!
3 OK, not quite yet.
Why PureScript?..instead of GHCJS?
• "Haskell in hindsight"
• Strict versus lazy
• Zero runtime
• Clean, easy FFI
• Great re-use of third-party JS
• Simpler language than GHC's quadrillion dialects of Haskell
Ecosystem
EcosystemUI Libraries
• purescript-halogen
• purescript-react
• purescript-angular
• purescript-rx
• purescript-flare
• purescript-pux
• purescript-optic-ui
• purescript-behaviors
• purescript-signal
• purescript-thermite
• purescript-frp-rabbit
• purescript-sigment
• purescript-ufi
And even more!
EcosystemTesting Libraries
• purescript-test-unit
• purescript-quickcheck
• purescript-quickcheck-laws
• purescript-strongcheck
• purescript-benchotron
• purescript-spec
• purescript-assert
EcosystemPreludes4
• purescript-prelude• purescript-preface• purescript-batteries
4 Yes, there are multiple!
EcosystemBuild Tooling
• pulp• grunt-purescript• gulp-purescript• purescript-psa
EcosystemEditor / IDE Support
• Atom
• purescript-contrib/atom-language-purescript
• nwolverson/atom-ide-purescript
• Emacs
• dysinger/purescript-mode
• emacs-pe/purescript-mode
• ardumont/psci-mode
• spion/purscheck
• emacs-pe/flycheck-purescript
• epost/psc-ide-emacs
• Sublime Text 2 - PureScript package
• Vim
• purescript-vim
• FrigoEU/psc-ide-vim
• IntelliJ IDEA - ikarienator/pure-idea
• Visual Studio - nwolverson/vscode-ide-purescript
• General
• kRITZCREEK/psc-ide
• To generate TAGS files, use psc-docs --format etags (or --format ctags)
Getting StartedPrerequisites
1. Node.js
2. NPM
3. Bower
4. PureScript
5. Pulp
Getting StartedPrerequisites: Node.js
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
Node.js allows full-featured, browser-less Javascript programs.
Getting StartedPrerequisites: Node.js
• Many Javascript dev tools are written in Javascript and run on Node.js
• PureScript dev tools are written in PureScript, compiled to JavaScript
• Bottom Line: You can't live without it (even if you want to!).
Getting StartedPrerequisites: Node.js
• Installers
https://nodejs.org/en/download/
• Homebrew
brew install node
• MacPorts
port install nodejs
• pkgsrc
pkgin -y install nodejs
• Debian / Ubunutu (4.x)
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
• Debian / Ubuntu (6.x)
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Getting StartedPrerequisites: NPM
• NPM = Node Package Manager
• Used by Node to manage packages
• Many tools and libraries are distributed through NPM
• Bottom Line: Another thing you can't live without...
Getting StartedPrerequisites: NPM
• NPM comes pre-installed with Node.js but version may be old
• Self-Updating NPM:
sudo npm install npm -g
Getting StartedPrerequisites: Bower
• A package manager for the web
• Maintains global registry of name -> URL
• Supports repositories & tags
• Supports all types of dependencies (binary, PureScript, etc.)
• Dependencies specified in bower.json file
• Bottom Line: Almost all PureScript libraries are registered with bower, and almost all PureScript projects maintain dependencies with bower!
Getting StartedPrerequisites: Bower
{ "name": "purescript-library", "description": "A PureScript library", "authors": [ "John A. De Goes <[email protected]>" ], "license": "Apache 2", "version": "0.1.0", "ignore": [ "**/.*", "node_modules", "bower_components", "output" ], "dependencies": { "purescript-profunctor-lenses": "^1.0.0-rc.1", "purescript-free": "^1.0.0-rc.1", "purescript-console": "^v1.0.0-rc.1", "purescript-either": "^v1.0.0-rc.1", "purescript-maybe": "^1.0.0-rc.1", "purescript-foldable-traversable": "^1.0.0-rc.1", "purescript-monoid": "^1.0.0-rc.2", "purescript-bifunctors": "^1.0.0-rc.1", "purescript-invariant": "^1.0.0-rc.1", "purescript-prelude": "^1.0.0-rc.4", "purescript-control": "^1.0.0-rc.1", "purescript-transformers": "^1.0.0-rc.1" }}
Getting StartedPrerequisites: Bower
• Install with NPMnpm install -g bower
Getting StartedPrerequisites: PureScript Compiler
• psc — PureScript compiler
• psc-docs — PureScript documentation generator
• psc-bundle — Bundler & dead-code eliminator
• psci — PureScript Read-Eval-Print-Loop (REPL)
• psc-ide-server — IDE Server
• psc-ide-client — IDE Client
Getting StartedPrerequisites: PureScript Compiler
• Installers
https://github.com/purescript/purescript/releases/latest
• Install with NPM
npm install -g purescript
Getting StartedPrerequisites: Pulp
• Pulp: Popular build tool for PureScript projects
• Knows how to perform magical incantations of psc & related tools
• Bottom Line: If you can use it to build your project, then do it!
Getting StartedPrerequisites: Pulp
• Install with NPMnpm install -g pulp
Getting StartedHello World
1. Create Directory Structure
2. Create Bower File
3. Install Bower Dependencies
4. Write PureScript Main
5. Build & Run
Getting StartedHello World: Create Directory Structure
bower.json/src/ /Main.purs
Getting StartedHello World: Create Bower File
{ "name": "hello world", "dependencies": { "purescript-console": "^0.1.1", "purescript-eff": "^0.1.2", "purescript-prelude": "^0.1.5" }}
Getting StartedHello World: Install Bower Dependencies
bower install
Getting StartedHello World: Write PureScript Main
module Main whereimport Prelude(Unit)import Control.Monad.Eff (Eff)import Control.Monad.Eff.Console (CONSOLE, log)main :: forall e. Eff (console :: CONSOLE | e) Unitmain = do log "Hello World!"
Getting StartedHello World: Build & Run
pulp buildpulp run
Congratulations, You've Started Your Journey Into The World of PureScript!
Don't Forget the Easy Peasy PureScript Workshop at LambdaConf 2016!
More Resources: http://purescript.org
THE END