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
0
votes
1 answer

How to handle effects with Pux?

I'm just a beginner to the whole world of Purescript and Pux, so I'm a little confused as to where we handle effects. Currently I'm modelling the effects in my type: type State = { countries ∷ Maybe (Eff (random :: RANDOM) Countries) } And then…
Wildhoney
  • 4,969
  • 33
  • 38
0
votes
1 answer

purescript anonymous function arguments on nested records?

Is it possible to apply anonymous function arguments to nested records somehow in the followign way? type UName = {fname :: String, lname :: String} type XName = { xname :: UName, addr :: String} updateU = _ { xname : { fname : _ } } -- not ok --…
Gspia
  • 809
  • 6
  • 15
0
votes
1 answer

Parsing list of list of ints with overlapping separators purescript-string-parsers

Let me use this example: 1 2 3 / 4 5 6 should parse into: [[1, 2, 3], [4, 5, 6]] So I write: p1 :: Parser (List Char) p1 = sepBy anyDigit (char ' ') p2 :: Parser (List (List Char)) p2 = sepBy p1 (string " / ") Alas, this fails: (Left Character…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
1 answer

How to make a phantom applicative functor in PureScript?

I'm reading through this paper and it says that Monoids are phantom applicative functors. I tried setting up a phantom type in purescript but I get a type error in the Functor instance. My guess is the compiler doesn't know what the a is in Accy o…
Albtzrly
  • 924
  • 1
  • 6
  • 15
0
votes
0 answers

Purescript error - can't match equivalent types?

Error found: in module Test at /Users/arahael/dev/test/test.purs line 14, column 37 - line 14, column 59 Could not match constrained type (Spreadable a0) => Array a0 -> Int with type (Spreadable a1) => Array a1 -> Int while trying…
Arafangion
  • 11,517
  • 1
  • 40
  • 72
0
votes
2 answers

The value of x is undefined here, so this reference is not allowed

I wrote a very simple parser combinator library which seems to work alright (https://github.com/mukeshsoni/tinyparsec). I then tried writing parser for json with the library. The code for the json parser is here -…
Mukesh Soni
  • 6,646
  • 3
  • 30
  • 37
0
votes
1 answer

Duplicate exception error

Trying to call Eff from within Aff: import Prelude import Control.Monad.Aff (Aff, launchAff) import Control.Monad.Eff (Eff) import Control.Monad.Eff.Class (liftEff) import Control.Monad.Eff.Console (CONSOLE, log) import Control.Monad.Eff.Exception…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
1 answer

Purescript Eff Monad: using non-native computational effects

I want to be able to write x :: Eff (reader :: Reader Int, maybe :: Maybe) Int x = do config <- ask -- configuration from (Reader Int) monad just config -- using (Maybe) Monad runX :: Int runX = runPure (runMaybe doIfNothing (runReader 6 x)) --…
0
votes
1 answer

Unifying record type

As a learning exercise, I'm trying to define a newtype to serve as a holder of functions that can convert Show-able values to Effects, i.e.: newtype ShEff a = ShEff (forall eff. Show a => a -> Eff eff Unit) However, this: f :: forall a. ShEff a f =…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
2 answers

throwError in Halogen component queries

I'm struggling with achieving following goal: I have the API requests typed in a manner that they return either a desired value, or an error when the status code wasn't indicating success, or when the auth token has been invalid etc: Either String…
Bartosz
  • 3,318
  • 21
  • 31
0
votes
1 answer

Purescript Halogen DeepPeek Child Instead of Grandchild

I'm trying to adapt this example https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58 (relevant part copied below), but instead of peeking the grandchild I just want to peek the child, or in this case…
sportanova
  • 125
  • 3
  • 8
0
votes
1 answer

Foreign import of a newtype over a record

If I have some javascript json data, can I foreign import that data over a user-defined newtype, but with a subset of the actual data? For example: in javascript: exports.foo = {foo: "foo", bar: "bar"} in purescript: newtype Foo = Foo {foo ::…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
0
votes
2 answers

Filter array of arrays in purescript

Doing this in psci: > filter (\[a,b] -> a > 1) [[1,2],[3,4]] results in a compile error: A case expression could not be determined to cover all inputs. due to [a,b] possibly failing to match, which makes sense. I know I can do this: > :p … let f…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
2 answers

runSignal works in the browser but not on the node console

I have been playing with purescript and signals. I have a block of code runSignal $ (every 2000.0) ~> logShow which when compiled into a JS file(pulp browserify) as main = do runSignal $ (every 2000.0) ~> logShow and executed on the…
0
votes
1 answer

Monad reader and partial application of functions

Since partially applied functions are instances of the MonadReader, why is the following code incorrect? runReader (\x -> x + 2) 4 or even runReader (\x -> pure $ x + 2) 4
z1naOK9nu8iY5A
  • 903
  • 7
  • 22