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
5 answers

Put adjacent elements in List into Tuples

Given a List of elements: xs = [a, b, c, d, ... z] where a, b, c etc are placeholders for arbitrary values. I want to implement a function adjacents :: [a] -> [(a, a)] that produces adjacentValues = [(a, b), (b, c), (c, d), ... (y, z)] In…
Anatol
  • 191
  • 6
0
votes
1 answer

Purescript cannot get keycode from keyboard

I am new to functional programming and to Purescript. I am trying to get keycode from keys pressed from keyboard. I have made a eventListener which fires when keydown event is fired and triggers event listener function test. I am having problem in…
0
votes
1 answer

couchdb server admin created in script cannot create database in the same script

In the same script, I can succesfully create a server admin on the /_config/admins/, then log in as that admin on the _session endpoint. The response is: {"ok":true,"name":"cor","roles":["_admin"]} However, I then cannot create a database:…
0
votes
1 answer

generalize purescript function using MonadAff

I have a question about generalizing. Starting with this function: test0 :: String -> String test0 s = s we can generalize it in its argument: test1 :: forall a. Show a => a -> String test1 s = show s or in its functional result: test12 :: forall…
0
votes
1 answer

Monads do not compose, right?

While I was researching for a talk I came across something that I thought was not possible, and I still can't figure out why it is working. In the Control.Bind module, there is the definition of the fish operator: composeKleisli ∷ ∀ a b c m. Bind m…
Regis Kuckaertz
  • 991
  • 5
  • 14
0
votes
0 answers

Purescript ScreenX and ScreenY not working

I am new to purescript and was trying to make a 3d cube rotate on mouse events. ScreenX and ScreenY is not working and I cannot get x and y coordinates of mouse pointer on mouse move event. I am attaching my code below which have a event listener.…
0
votes
1 answer

Purescript MouseEvent to get x y of mouse

I am new to purescript and was trying to make a 3d cube rotate on mouse events. But I cannot get x and y coordinates of mouse pointer on mouse move event. I am attaching my code below which have a event listener. Can somebody help me in getting x…
0
votes
1 answer

How to log a Maybe value?

I wrote this code (based on the AddressBook example in PureScript by Example) findEntry :: String -> String -> AddressBook -> Maybe Entry findEntry firstName lastName = head <<< filter filterEntry where filterEntry :: Entry -> Boolean …
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

catchException doesn't remove the effect

In the module below, function g compiles without no comment but function f gives the message "Could not match type", with the explanation that (err :: Exception | e) does not match (). However, both throwException and toISOString return a value in…
0
votes
1 answer

How do I index an element from an array consisting of arrays in purescript?

a = [ 1, 2, 3] a [1,2,3] b = [ 3, 4, 5] b [3,4,5] c = [a ,b] c [[1,2,3],[3,4,5]] a !! 2 (Just 3) a !! 2 (Just 3) a !! 1 (Just 2) c !! 2 Nothing c !! 1 (Just [3,4,5]) c !! 1 !! 0 Error found: in module $PSCI at line 1,…
Ankit Agrawal
  • 11
  • 1
  • 4
0
votes
1 answer

Strange behaviour of unwrap (purescript-signal)

Looking at purescript-signal examples, I have seen that a common pattern is to use a pure update function and an effectful render function this way: runSignal $ map render (foldp update initialState input) But what to do if rendering needs to keep…
cmant
  • 453
  • 1
  • 5
  • 11
0
votes
1 answer

How is this type inferred?

Digging through the source: https://github.com/slamdata/purescript-affjax/blob/v5.0.0/src/Network/HTTP/Affjax.purs#L92 stumbled upon the signature of get: get :: forall e a. Respondable a => URL -> Affjax e a and ventured into psci: > import…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
2 answers

How to create Functor instance for Type composed of Either and Maybe

I'm having trouble with a Functor instance for a type which is basically just nested Either and Maybe. data Tuple a b = Tuple a b data Primitive = String String | Boolean Boolean | Number Number | Null data JsonValue = Object (Map String JsonValue)…
user149327
  • 461
  • 4
  • 4
0
votes
2 answers

Purescript Halogen Component, Input vs State

I want to make a Halogen Component where the component's input differs from its state. According to the guide for Halogen (https://github.com/slamdata/purescript-halogen/blob/master/docs/5%20-%20Parent%20and%20child%20components.md#input-values)…
0
votes
1 answer

Adding a componentDidMount event listener to a PureScript Thermite component

My goal is to call a remote api in order to populate a Purescript Thermite component at startup, for this I need (I think) the componentDidMount event handler which is not directly available on Thermite but is exposed by the lower level react…
mmai
  • 715
  • 1
  • 7
  • 15