Questions tagged [purescript]

PureScript is a functional language with strong, static types which compiles to JavaScript.

PureScript is a small strongly, statically typed programming language with expressive types, written in and inspired by , and compiling to .

PureScript has a number of interesting features, such as:

  • 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

Sample "Hello word" :

import Control.Monad.Eff.Console

main = do
    log "Hello, PureScript"

Would be compiled into:

var Control_Monad_Eff_Console = require("Control.Monad.Eff.Console");
var main = Control_Monad_Eff_Console.log("Hello sailor!");
module.exports = {
    main: main
};

References:

591 questions
34
votes
1 answer

What are Eff and Aff?

What is the relationship between the Purescript types Eff and Aff? Is it possible to convert between them? I'm just starting out with Purescript coming from Haskell, and it seems like both types roughly serve the role that IO has in Haskell. Is that…
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
21
votes
2 answers

what are the differences between Haskell and PureScript?

PureScript looks very similar to Haskell. It seems to me that large parts, mostly the pure parts, of a PureScript program should be compilable as well by a Haskell compiler. Is that right? This leads to a related questions: Would it be possible to…
Thomas Koch
  • 2,833
  • 2
  • 28
  • 36
17
votes
1 answer

In PureScript, how does List differ from Array?

In PureScript, how does List differ from Array? What are the reasons to use one over the other?
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
16
votes
0 answers

What properties of profunctors do not make it into Haskell/PureScript?

In their paper on profunctor optics, Pickering et al. state that The term ‘profunctor’ comes from category theory, although much of the categorical structure gets lost in translation. That seems odd and kind of unique to me, as other algebraic…
16
votes
4 answers

Creating PureScript records from inconsistent JavaScript objects

Assume I have User records in my PureScript code with the following type: { id :: Number , username :: String , email :: Maybe String , isActive :: Boolean } A CommonJS module is derived from the PureScript code. Exported User-related…
davidchambers
  • 23,918
  • 16
  • 76
  • 105
15
votes
1 answer

How do you compose functions in PureScript?

Tried to use (.) for function composition, but it doesn't work. import Data.String (length, trim) trimmedLength :: String -> Int trimmedLength = length . trim
dontexist
  • 5,252
  • 4
  • 27
  • 51
13
votes
3 answers

Understanding the Reader monad

I'm reading PureScript by Example and got to the part introducing the Reader monad. The example goes like this: createUser :: Reader Permissions (Maybe User) createUser = do permissions <- ask if hasPermission "admin" permissions then map…
kaqqao
  • 12,984
  • 10
  • 64
  • 118
13
votes
1 answer

String Concatenation in Purescript

Playing with purescript and running into an odd problem with string concatenation. I've loaded and imported the Prelude, Data.List, Data.Maybe, and Data.String (also, tried importing Data.Array) but the PSCi still doesn't recognize (++). This would…
Tshimanga
  • 845
  • 6
  • 16
12
votes
2 answers

How to combine rows of record types in PureScript? (Is there any alternative to the Union typeclass in PureScript 0.12.0?)

Problem: I have different record types with many common fields. How could I "include" the common fields in the record type definitions? Example: newtype RecordType1 = RecordType1 { a :: Int, b :: Int, y :: String } newtype RecordType2 = RecordType2…
Digital Stoic
  • 1,229
  • 11
  • 20
12
votes
1 answer

Convert an array to a list in PureScript

XY problem How do I convert an array to a list in PureScript? arrayToList :: forall a. Array a -> List a arrayToList = ??? Actual problem Must I necessarily write this function? Neither purescript-arrays nor purescript-lists define such a…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
12
votes
1 answer

PureScript FFI to mocha

I am trying to write mocha bindings into PureScript and am completely baffled by Control.Monad.Eff describe(function(){ //do stuff }); Describe is a function that takes nothing and returns IO, or Eff or something that means (side-effect…
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
11
votes
2 answers

How to read a file in PureScript (readFile)

While testing, I’d like to read and write a file from and to disk (JSON in, JSON out). How do I do this in PureScript? In Haskell I have something like main :: IO () main = do input <- readFile "input.json" writeFile "output.json" $ process…
0dB
  • 675
  • 5
  • 13
10
votes
1 answer

Need help on start using purescript on NixOS

I am trying to setup hello world project with purescript on NixOs and have couple questions, Official purescript website recommend installation via npm but there is no nixos.nodePackages.purescript, instead there are at least 2 variants I found in…
wizzup
  • 2,361
  • 20
  • 34
10
votes
2 answers

Combine Records in Purescript

Given I have the folowing records in purescript: let name = {name: "Jim"} let age = {age: 37} is it possible to combine those two records some how in a generic way? Something like: name 'comb' age such that I get the following record: {name:…
Tim de Putter
  • 281
  • 1
  • 2
  • 10
10
votes
4 answers

How can I encode and enforce legal FSM state transitions with a type system?

Suppose I have a type Thing with a state property A | B | C, and legal state transitions are A->B, A->C, C->A. I could write: transitionToA :: Thing -> Maybe Thing which would return Nothing if Thing was in a state which cannot transition to A. But…
Mark Bolusmjak
  • 23,606
  • 10
  • 74
  • 129
1
2 3
39 40