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

Decoding Union types in purescript

I am using purescript-agronauth library to manually encode and decode the following types to json and back. But the following does not work data Attributes = TextAlignment TextAlign | TextScale String | LineHeight String instance…
0
votes
1 answer

Getting "An infinite type was inferred for an expression" for query'/request from Halogen

In my component: data Query a = SetImageUrl Int String a Main (app) component: eval :: Query ~> H.ParentDSL State Query ChildQuery ChildSlot Void m eval = case _ of HandleItemChange groupId (LIS.ActiveChanged selected) next -> do let…
menfon
  • 1,587
  • 1
  • 11
  • 28
0
votes
2 answers

How to convert between ADTs with lenses in purescript?

This is code is a working but simplified example of what I want to accomplish. I want to map from one type wrapping records into another: import Prelude import Data.Lens import Data.String as String newtype AsString = AsString { names :: Array…
DerKastellan
  • 143
  • 2
  • 7
0
votes
2 answers

Purescript guard fails with: No type class instance found for Control.MonadZero.MonadZero Identity

visitNode :: Castle -> State (Set Castle) Unit visitNode c = do s <- get guard $ not (member c s) modify \acc -> insert c s I have some simple code for visiting nodes represented by a custom datatype. I thought MonadZero control…
superoven
  • 3
  • 3
0
votes
1 answer

How to implement twice function (function that executes other function twice)? Could not match type Record with type Function Int

Here is the code module Main where import Prelude twice1 f = f . f transform :: Int -> Int transform n = n + 1 apply1 x = (twice1 transform) x I have an error Could not match type Record with type Function Int What's wrong?…
srghma
  • 4,770
  • 2
  • 38
  • 54
0
votes
1 answer

aff-ify a function that has different resulting types in error and success callback

Let's first look at a similar function from the web-gl package, for which the intention works: withShaders :: forall bindings eff a . Shaders ({ | bindings }) -> (String -> EffWebGL eff a) -> ({ webGLProgram :: WebGLProg | bindings } ->…
Micha
  • 53
  • 5
0
votes
1 answer

How to add insert an element after another?

PureScript's purescript-jquery package supports this before :: JQuery -> JQuery -> Effect Unit method, which "Inserts an element before another" as shown in its documentation on pursuit. Is there a similar function somewhere, which inserts an…
mherzl
  • 5,624
  • 6
  • 34
  • 75
0
votes
1 answer

What's wrong with this purescript constructor?

Trying to create a constructor for roman digits: data RomanDigit a = M | D | C | L | V | I newRomanDigit :: Int -> RomanDigit newRomanDigit 1000 = M newRomanDigit 500 = D gets error message: in module UserMod at src\UserMod.purs line 81, column…
vt5491
  • 2,254
  • 2
  • 22
  • 34
0
votes
1 answer

How to quickCheck on custom ADT in PureScript?

For using QuickCheck, I'm trying to implement the Arbitrary instance: import Test.QuickCheck import Test.QuickCheck.Arbitrary (class Arbitrary, class Coarbitrary) data Arith = Lit Int | Add Arith Arith | Neg Arith derive instance arithEq :: Eq…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
0
votes
2 answers

How do I convert a string to a list of chars in purescript?

I have searched pursuit, only two of them seems matchs well : charList from purescript-optlicative (module: Node.Optlicative.Internal) toChars from purescript-yarn (module: Data.String.Yarn) And both yarn and optlicative is not available with…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
0
votes
1 answer

How to implement an Eff-like monad without foreign interface

I am interested in implementing something like Freer Monads, more Extensible Effects in PureScript, but using rows rather than an open union (I suppose it is possible). However, I wasn't able to define a kind without foreign import. I want to be…
0
votes
2 answers

Error running purescript example

I'm trying to learn purescript starting with the simple "Hello World" from "Purescript by Example". Issuing a "pulp run" throws this error: * Building project in /home/peter/devel/purescript/my-project Error found: at…
0
votes
2 answers

How exactly does operator <> work in Purescript?

Being new to Purescript, I am struggling to figure out why the following code (taken from "PureScript By Example") works as it does: > flip (\n s -> show n <> s) "Ten" 10 "10Ten" This makes sense to me: flip calls its first argument (the lambda…
Angle.Bracket
  • 1,438
  • 13
  • 29
0
votes
1 answer

PureScript Halogen coordinates of the element on the page

How do I get the coordinates of the element itself on the page that triggered this event when I hover over it? In purescript there is an opportunity to take page, screen and client coordinates. Is it possible to know the coordinates of the element…
0
votes
1 answer

Type checking error useing random in purescript

With the following code insertRnd works properly but I can't get scramble or anything else that uses insertRnd to compile: scramble :: ∀ eff. String -> Eff (random :: RANDOM | eff) String scramble s = foldl insertRnd (take 1 s) (drop 1 s) insertRnd…