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

Why is this type class instance failed to unify?

I am trying to write Redux-like store in PureScript. I defined Action type class and algebraic data types for each actions to divide to smaller modules. class Action a data FooAction = UpdateFoo String | ResetFoo data BarAction = UpdateBar…
katashin
  • 33
  • 5
0
votes
1 answer

Correct way to download a binary file from server using PureScript and Pulp

I have a simple javascript function that creates an XMLHttpRequest , runs it (synchronously to make things as simple as possible) and returns an array that is the result. exports.loadBinFile = function() { ... } I have that script in a js file,…
PsyFish
  • 287
  • 1
  • 9
0
votes
2 answers

How to concatenate strings and variables so that quotes in the variables are escaped?

I am using readJSON which, in case of error, yields Left err. Sometimes this error (a string) contains quotation marks, e. g. ReferenceError: "JSON" is not defined. I need to return this error wrapped in a JSON string, sort of like Left err -> "{…
0dB
  • 675
  • 5
  • 13
0
votes
2 answers

Purescript pulp build output generates requirejs error in browser

When I use pulp build -O -t html/main.js and then pulp build -O -I test -m Test.Main -t html/testmain.js (i.e. building main and test) I get two different js output. In the former case, the format is // Generated by psc-bundle 0.8.2.0 var PS = {…
user2039784
  • 199
  • 9
0
votes
2 answers

Is there a more elegant way to do search for max and conversion to Int

given the following function maxInt :: Array Number -> Int maxInt xs = fromMaybe 0 $ join $ fromNumber <$> maximum xs maxInt [ 2.0, 4.0, 1.0, 5.0 ] => 5 Is there some a more elegant way to do this? There is a lot of stripping away Maybes
robkuz
  • 9,488
  • 5
  • 29
  • 50
0
votes
2 answers

How can I return a Maybe value from do notation in PureScript?

I'm trying to return a Maybe value from a function that uses do notation, but I can't seem to get it to work. This function takes a string (The "filename") and a Path to search in... findIn :: String -> Path -> Maybe Path findIn search start = do …
Albtzrly
  • 924
  • 1
  • 6
  • 15
0
votes
1 answer

Purescript Halogen Component function: Passing spaced arguments instead of a Record?

I'm on PureScript 0.8.2. In PureScript Halogen, the component function has the signature: component :: forall s f g. ComponentSpec s f g -> Component s f g where -- | A spec for a component. type ComponentSpec s f g = { render :: s ->…
RAbraham
  • 5,956
  • 8
  • 45
  • 80
0
votes
2 answers

How can I create an array with polymorphic data?

I am trying to do this data Foo a = Foo a data FooWrapper = FooWrapper (forall a. Foo a) foo = [FooWrapper (Foo 0), FooWrapper (Foo "")] But there is an error Could not match type Int with type a0
ais
  • 2,514
  • 2
  • 17
  • 24
0
votes
1 answer

Mysterious syntax error converting a D3 vis from Javascript to Purescript

I am converting a D3 visualisation from Javascript to Purescript and i get a syntax error while trying to save a selection within a do block. This is the code: enterCountry country = do sel <- select "g.root" .. selectAll "g.country" ..…
danza
  • 11,511
  • 8
  • 40
  • 47
0
votes
1 answer

Use purescript-halogen (with pulp)

Following PureScript by Example, I'm using pulp for installing packages. Halogen requires virtual-dom as extra dependency. From the documentation and the example packages, it seems to me that adding it involves a bunch of build tools that I haven't…
András Kovács
  • 29,931
  • 3
  • 53
  • 99
0
votes
2 answers

When function should be effectful?

When I use FFI to wrap some API (for example DOM API) is there any rule of thumb that could help me to decide whether function should be effectful or not? Here is an example: foreign import querySelectorImpl """ function querySelectorImpl…
starper
  • 175
  • 1
  • 8
0
votes
1 answer

PureScript Type Error is hard to understand

This compiles foo ma = case ma of [Just a] -> newRVar 0 >>= a view :: forall a eff. M.Map String (Linker Number a eff) -> String -> Eff (reactive :: Reactive |…
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
0
votes
1 answer

adding to do block, stops code execution

foreign import subscribeEventedOnPrime "function subscribeEventedOnPrime(n){ \ \ return function(fn){ \ \ return function(obj){ \ \ return function(){ \ \ obj.addEventListener(n,…
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
-1
votes
1 answer

How do I get the current browser URL with purescript?

How do I get the the browser URL in Purescript, just like when doing window.location.href in javascript?
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
-1
votes
1 answer

How to have row without particular field as function param

What I want is following, I have a row type: type FooBarBaz = ( foo :: Int , bar :: String , baz :: Boolean ) Then a need a function that takes this row type record but without "foo": and adds default "foo" field: withoutFoo { bar: "bar",…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
1 2 3
39
40