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

Learning Purescript, some help defining types

I'm new to Functional Programming. I've used Ramda a bit (JavaScript library), but nothing like the type system in Purescript. I have an idea that I feel should be expressible with Purescript's type system, but I'm not really sure where to…
Mrk Sef
  • 7,557
  • 1
  • 9
  • 21
0
votes
1 answer

No type class instance was found, the instance head contains unknown type variables

Well, just simplified as possible: There is a function that takes functor and does whatever sToInt :: ∀ a s. Functor s => s a -> Int sToInt val = unsafeCoerce val Usage of this function with functor S which param (v) is functor too. -- declare date…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
0
votes
0 answers

What is preferred way to implement uniq or uniqBy filter for Array/List?

There seems no straight implementing uniq or uniqBy filter for Array/List ["val1", "val2", "val1"] -> ["val1", "val2"] ["key1" /\ 1, "key2" /\ 10, "key1" /\ 20] -> ["key1" /\ 1, "key2" /\ 10] There can be many ways of doing this, but what is the…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
0
votes
1 answer

Unique symbol value on type level

Is it possible to have some kind of unique symbol value on the type level, that could be used to distinct (tag) some record without the need to supply a unique string value? In JS there is Symbol often used for such things. But I would like to have…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
0
votes
1 answer

API for handling polymothinc records

It is a little bit custom issue, is not contrived, but just simplified as possible. -- this record that has fn that handles both x and y, -- x and y supposed to be Functors, a arbitrary param for x/y, r is arbitrary result param type R0 a x y r = …
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
0
votes
1 answer

ConstrainedTypeUnified error from Prim.Union

I want to define a Record type Rec3 as the union of two rows so that I can use Rec3 as the argument for function func1. import Prim.Row (class Union) type Row1 = (x1 :: Int) type Row2 = (x2 :: String) type Rec3 = forall r. Union Row1 Row2 r =>…
James Brock
  • 3,236
  • 1
  • 28
  • 33
0
votes
1 answer

Purescript define cons as typeclass operator

Cons operator is defined (:) is defined for Array (Array.cons) and List (Cons type constructor). So to use it in the code we should either: import Data.List ((:)) or import Data.Array ((:)) I wonder if it is possilbe to to define (:) so that it…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
0
votes
0 answers

How to trace values of a recursive PureScript function in the repl?

With this Main.purs (excluding imports): main :: Effect Unit main = pure foo foo :: Unit foo = trace "foo" (\_ -> unit) This works as expected with both pulp repl and pulp run: > import Main > foo 'foo' unit > :q See ya! $ pulp run * Building…
codenoodle
  • 982
  • 6
  • 19
0
votes
2 answers

How are state monads / monad transformers desugared inside do notation?

Example sumArray :: Array Int -> State Int Unit sumArray = traverse_ \n -> modify \sum -> sum + n t1 :: Int t1 = execState (do sumArray [1, 2, 3] sumArray [4, 5] sumArray [6]) 0 -- returns 21 module Main where import Prelude import Effect…
0
votes
1 answer

How to parse row-polymorphic records with SimpleJSON in PureScript?

I wrote a utility type and function that is meant to aid in parsing certain row-polymorphic types (sepcifically, in my case, anything that extends BaseIdRows: type IdTypePairF r = (identifier :: Foreign, identifierType :: Foreign |…
bbarker
  • 11,636
  • 9
  • 38
  • 62
0
votes
1 answer

Ord: No type class instance was found for Data.Eq.Eq (Extended a0). PureScript by Example book, Chapter 6

I am quite new to Haskell/Purescript and currently learning by studying the PureScript by Example book. In chapter 6 about type classes, exercise 4 has following task: (Medium) Given any type a with an instance of Ord, we can add a new "infinite"…
bela53
  • 3,040
  • 12
  • 27
0
votes
1 answer

Combining lists of variants of different types in purescript

I have been playing around with Purescript as a means of experimenting with programming in a Haskell-like language with row and column polymorphism. In particular, using Purescript's variant package, I was trying to write an operation to combine two…
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
0
votes
1 answer

No type class instance error when trying to lift Aff response

I am a newbie to Purescript and am trying to learn Halogen/Aff. I have been working on a simple app which is a variation of the effects-aff-ajax example in the purescript-halogen repo. I have everything almost working, except I get the error…
brown131
  • 11
  • 2
0
votes
1 answer

NodeJS app failed with "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch"

I am getting error saying Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch when I try to start the app, I am pretty sure I've configured the app to use the $PORT env variable provided by Heroku, as I could…
leomayleomay
  • 553
  • 1
  • 7
  • 16
0
votes
1 answer

Purescript - How to define function signature in REPL?

When I type, say: f :: Int -> Int The REPL complaints with: The type declaration for f should be followed by its definition.
Ron
  • 7,588
  • 11
  • 38
  • 42