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
4
votes
2 answers

Similar record types in a list/array in purescript

Is there any way to do something like first = {x:0} second = {x:1,y:1} both = [first, second] such that both is inferred as {x::Int | r} or something like that? I've tried a few things: [{x:3}] :: Array(forall r. {x::Int|r}) -- nope test = Nil…
Dax Fohl
  • 10,654
  • 6
  • 46
  • 90
4
votes
2 answers

Difference between "foreign import data Foo :: Type" and just "data Foo"

Is there any functional difference between the titular approaches in defining a foreign type? The foreign import data Foo :: Type approach makes the intention clearer, but is that it?
bklaric
  • 447
  • 6
  • 15
4
votes
4 answers

infer a type for common fields in two records

Bear with me if this is a foolish question. How can I type a generic function that takes two records and returns an array of their common fields? Let's say I have: type A = { name :: String, color :: String } type B = { name :: String, address ::…
Sam R.
  • 16,027
  • 12
  • 69
  • 122
4
votes
1 answer

How to get from `pulp init` to running code in browser?

I have success on getting pulp's helloworld purescript running via nodejs with following command sequences: $ pulp init ... $ pulp run * Building project in /data/works/beta_projects/js_games/processing/hello-ps * Build successful. Hello…
wizzup
  • 2,361
  • 20
  • 34
4
votes
2 answers

Purescript: Pattern match wildcard data constructor

While the example is contrived, why can I not use the wildcard pattern if the data constructor is ignored? module Main where import Prelude import Control.Monad.Eff.Console (log) data Person = Amy { name :: String } | George { name :: String …
M. Walker
  • 603
  • 4
  • 14
4
votes
1 answer

How to convert partial functions to safe(Maybe) functions?

I want it to use library-defined partialfunc more convenient, or write callback with partial pattern-matching. like this, partialMaybe :: forall a b. (Partial => a -> b) -> a -> Maybe b I couldn't find similar in some major libraries. How to define…
acple
  • 65
  • 3
4
votes
1 answer

Polymorphic types with purescript-bridge

I have type in Haskell newtype Uid a = Uid {uidToText :: Text} deriving (Eq, Ord, Show, Data, Typeable, Generic) Using purescript-bridge library mkSumType function I can't make SumType of it. Now I have clientTypes :: [SumType …
vrom911
  • 694
  • 1
  • 5
  • 16
4
votes
2 answers

How to map a 0-argument JavaScript function in PureScript FFI

I am trying to import the following JavaScript function into PureScript using the FFI: function getGreeting() { return "Hi, welcome to the show." } but I am not sure what the type should be. The closest I get to is something like: foreign import…
Rouan van Dalen
  • 748
  • 4
  • 14
4
votes
1 answer

Error could not match type

I have a type: newtype User = User { id :: String , email :: String , last_update :: String } and a function: import Pux.DOM.HTML (HTML) import Pux.DOM.HTML.Attributes (key) import Text.Smolder.HTML as H import Text.Smolder.HTML.Attributes…
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
4
votes
1 answer

What's the best way to "destroy" a purescript-halogen component when you're done using it?

I'm using Halogen to control a menu system for my application, and I'm wondering how I can "destroy" a Halogen component. Right now, I have a function that creates a submenu component on a div with a particular ID. Throughout the lifecycle of the…
Albtzrly
  • 924
  • 1
  • 6
  • 15
4
votes
2 answers

Idiomatic Haskell RLE in Purescript

So, I'm trying to learn Purescript by converting some Haskell code I had from the 99 Haskell Problems, and quickly got into a situation where I know how to solve it, but it is simply too ugly™. Here's the Haskell code for problems 10, 11 and 12;…
Hugo Sereno Ferreira
  • 8,600
  • 7
  • 46
  • 92
4
votes
1 answer

What exactly is considered a breaking change to a PureScript library?

The Rust community has a fairly detailed description of their interpretation of Semantic Versioning. The PureScript community has this, which includes: We should write a semver tutorial for beginners, specifically its use in PureScript and the way…
aij
  • 5,903
  • 3
  • 37
  • 41
4
votes
1 answer

How to render purescript-halogen components into the tag

How can I render a specific purescript-halogen component into the tag? The following example written for Halogen 1.0.0 renders the stylesheet and the paragraph into the HTML body: module Main where import Prelude import Control.Monad.Eff …
Siegfried Weber
  • 68
  • 1
  • 1
  • 7
4
votes
1 answer

(PureScript) How can I run a DOM event listener callback within a monadic context other than Eff?

I'm making a canvas game using PureScript and I'm wondering what the best way to handle event listeners is, particularly running the callbacks within a custom monad stack. This is my game stack... type BaseEffect e = Eff (canvas :: CANVAS, dom ::…
Albtzrly
  • 924
  • 1
  • 6
  • 15
4
votes
1 answer

Understanding Purescript Eff Monad and do blocks

I'm trying to understand why the following does not work in Purescript. I have a feeling it can also be answered by the Haskell community, thus I've cross listed it. The general gist is: If I have a do block, can I not throw in a disposable value?…
clo_jur
  • 1,359
  • 1
  • 11
  • 27