purescript - Difference Between MouseEvents

I am new to Purescript. I am working with MouseEvents from "import DOM.HTML.Event.EventTypes" and I couldn't understand the difference between Mouseup, Mousedown,Mouseout and Mouseleave. I searched for documentation but couldn't find an explanation for it. I would like to know when each of it is getting triggered....Read more

lens - 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 Preludeimport Data.Lensimport Data.String as Stringnewtype AsString = AsString { names :: Array String }newtype AsSize = AsSize { names :: Array Int }_names = lens _.names (_ { names = _ })to_sizes :: AsString -> AsSizeto_sizes (AsString s) = AsSize $ over (_names <<< traversed) String.length sHow do I do the same with lenses only and without unwrapping the record first?When using a lens...Read more

purescript - Access field of a record where field name is specified dynamically

In purescript, let's say I have a type.newtype Person = Person {name::String,age:Int}I want to create a function which takes this record and a string specifying the field name, e.g. name, and returns the value of that field.My use case is that I will have a record and I want concatanation of some of those fields. I want to pass an array of strings which will be the field names, and then using fold get it done in one line. Is such a thing possible?...Read more

Why does this function application generate a runtime error in purescript?

I have the following PureScript snippets; note parseXMLFromString is partially applied:parseXMLFromString ∷ String → DOMParser → Effect DocumentparseXMLFromString s d = parseFromString "application/xml" s dparseNoteDoc :: DOMParser -> Effect DocumentparseNoteDoc = parseXMLFromString TD.noteXmlnote <- parseNoteDoc domParserThe following code is generated:// Generated by purs version 0.12.4"use strict";var Effect_Console = require("../Effect.Console/index.js");var Test_Data = require("../Test.Data/index.js");var Web_DOM_DOMParser = require...Read more

Why is Unit in PureScript's Prelude {} in JavaScript?

I'm a beginner to FP and Type-level programming.I learned Void and Unit recently.Prelude's unit is defined as {} in JavaScript."use strict";exports.unit = {};My question is "Why not null but {}?"Maybe this is a trivial question, but I'd like to learn its philosophy.From my understanding, unit corresponds to null in JavaScript.For example, I can call a function with no arguments in JavaScript.// hello :: Void -> Stringfunction hello () { return "hello"}const h1 = hello() // "hello"// However, I do not have any members of `Void` in PureScript...Read more

purescript - How Can i Get to transform a Maybe to a Value?

I having a problem with my code I'm trying to compile it but it throws me Could Not Match Maybe Element with ElementWhy? how does Maybe Work?, how do I convert it to a Value? why is so hard to understand monads and functors,and why isn't an easy library to get some newbie getting started wit purescript?:P(for those who didn't understand I was just asking the first 3)module Main whereimport Prelude --(Unit, bind, pure, ($), (<$>))import Effect (Effect)import Data.Maybe --(Just,Maybe,fromJust, fromMaybe)import Data.Foldable (traverse_)impo...Read more

Get keyboard event in purescript

I want to get keydown event in purescript so I used DomEvent.Here is my code.main :: Eff (HA.HalogenEffects (console :: CONSOLE, timer :: T.TIMER)) Unitmain = HA.runHalogenAff do body <- HA.awaitBody cube <- runUI C.cubes unit body documenttarget <- liftEff $ window >>= document <#> DHT.htmlDocumentToEventTarget addEventListener (EventType "keydown") (eventListener test) true (documenttarget) H.liftEff $ T.setInterval (1000 / frameRate) do HA.runHalogenAff $ cube.query $ H.action C.TickWhen I try to run this code, I...Read more

purescript - Module x has been defined multiple times

I have installed some purescript packages using bower and here is my bower.json file.{ "name": "halogen-cube", "ignore": [ "**/.*", "node_modules", "bower_components", "output", "dist" ], "dependencies": { "purescript-prelude": "^3.1.1", "purescript-console": "^3.0.0", "purescript-halogen": "^2.0.0", "purescript-js-timers": "^3.0.0", "purescript-halogen-svg": "*" }, "devDependencies": { "purescript-psci-support": "^3.0.0" }}I wanted to add purescript-web-uievents package so I added "purescript-w...Read more

Understanding purescript-variant

Newbie here. I'm trying to understand some of the machinery behind purescript-variant. Basically what I mean is how to understand these 2 function: inj and on.When I look at the type of inj, the author makes use of Cons typeclasses. From my understanding, Cons place an assertion that there's a record r2 that can be made from some other record r1 by inserting a pair of tag/value. So in a sense: r1 + tag/value = r2And in this case Variant is the r2.Citing from the readme:foo :: forall v. Variant (foo :: Int | v)foo = inj (SProxy :: SProxy "foo") ...Read more

Global Resources in PureScript(for AWS Lambda)

I would like to run PureScript code in AWS Lambda. Normally, if a lambda function has to call the database, the connection is stored in a global variable. Excuse me if the following JavaScript code is syntactically wrong as I don't write JavaScript but something like below is what I want(this is the code expected by AWS Lambda):function createConnection() { connection = SomeDBLibrary.createConnection(username, pwd) return connection;}global.db_connection = createConnection();handler = (event, context, callback) => { // TODO use glob...Read more

Similar record types in a list/array in purescript

Is there any way to do something likefirst = {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}) -- nopetest = Nil :: List(forall r. {x::Int|r}){x:1} : test -- nopetype X r = {x::Int | r}test = Nil :: List(X) -- nopetest = Nil :: List(X()){x:1} : test{x:1, y:1} : test -- nopeEverything I can think of seems to tell me that combining records like this into a collect...Read more

purescript - Appropriate abstraction in lieu of heterogenous (but shared-class) list?

The ProblemI'm trying to write a game engine in PureScript. I'm new to it, but learning has been smooth since I've previously gone through Real World Haskell (though I haven't much experience using Haskell for "real" things, either). Anything that moves as many as possible of my runtime errors into compiletime errors, is a win in my book - but if the language proves to be overly restrictive of my ability to abstract away the problems, it can remove some of that win.Okay, so, I'm trying to build a 2d gaming engine in PureScript over the HTML5 Ca...Read more

PureScript and typeclasses

I'm having trouble with PureScript typeclasses. I have to say, up front, that I'm not a Haskell expert either so my apologies if these are obvious errors.I've tried several different approaches and hit a wall for each. I'm basically trying to define a show function for an edge in a graph. One approach looks like this:module Foo wheredata Edge n = Edge { from :: n, to :: n }instance showEdge :: (Show n) => Show (Edge n) where show e = "Edge from "++(show e.from)++" to "++(show e.to)e = Edge { from: 1, to: 2 }main = show eThis gives me the...Read more

How can I write a purescript effect handler that subracts an effect from the set

PureScript by Example, in the section The Eff Monad -> Handlers and Actions states that "[an effect] handler usually subtracts effects from the set". However, the examples are rather opaque and I can't work out how to write my own handler to achieve this.Specifically, I'm working with purescript-aff and purescript-affjax. I'd like to use runAff (from purescript-aff) in combination with get (from purescript-affjax).The problem is that get uses the Affjax monad, whereas runAff expects something using the Aff monad.Affjax is defined as:type Affjax...Read more