608 questions
1
vote
1
answer
48
views
Why eta-reduced of genericShow-based show definition overflows stack for recursive types
Consider the following recursive data type:
data Chain a = End | Link a (Chain a)
By deriving a Generic instance for this recursive type, show can be defined in terms of genericShow:
derive instance ...
1
vote
1
answer
107
views
Confused about do notation
I'm barely getting started with Purescript, and I hit a snag quite quickly. Consider the simple (and very artificial) example below:
module Main where
import Prelude
import Data.String.Common (...
1
vote
1
answer
57
views
Handling complex JSON with enums and variable sub-JSON schemas
I have a complex JSON which can have variable sub-JSONs inside it, each with their own schema. Here is an illustration of its structure:
[
"node_level": "unit",
"name"...
0
votes
1
answer
249
views
Spago failing to install PureScript dependencies due to Git error: 'destination path . already exists and is not an empty directory' on NixOS
I'm trying to get a hello-world Purescript project working on NixOS, and am encountering an error trying to get spago to build it. The installation of dependencies fails with the following error:
[...
0
votes
1
answer
52
views
Adding missing "method" attribute in Purescript-Halogen
Apparently, Halogen lacks "dialog" value of method attribute. As of writing the words, the method attribute in Halogen has only get and post values.
The good news though is Halogen says that ...
1
vote
2
answers
199
views
How to make build system produce multiple js outputs?
This would seem like a basic question, but I found no information on it. Websites don't typically consist of a single page. E.g. Stack Overflow has a menu on the left with Home, Questions, Tags links, ...
0
votes
2
answers
79
views
PureScript: how to wait for child to exit?
I'm writing a backend, and I need to execute certain command with text passed via stdin, then read the result from stdout. Such utilities provided by Node.ChildProcess module, except I don't see any ...
1
vote
1
answer
54
views
How to make different record `type`s unequal
I am learning PureScript due to not being satisfied (in particular) with TypeScript's type safety of what's called "records" in PS. While doing so I stumble upon the exact same problem in PS,...
2
votes
1
answer
265
views
Error installing spago@next using npm on node:22 Docker image
I am trying to set up a Docker development environment with PureScript. While trying to install Spago I get an error from the Docker builder. I am using the "node:22" image as a starting ...
2
votes
2
answers
258
views
What does "parameterised type in the positive / negative position" mean in the context of invariant functors?
From PureScript's Data.Functor.Invariant documentation (emphasis mine):
A type of functor that can be used to adapt the type of a wrapped function where the parameterised type occurs in both the ...
7
votes
0
answers
168
views
Where does the name of the `pure` function in the `Applicative` type class come from?
At this point in my learning journey, I simply accepted that this function is called pure (both in Haskell and in PureScript), but it would have helped a lot if I had known the reasoning behind this ...
1
vote
1
answer
67
views
Why is the `Data.Int` type not a `Semigroup` in PureScript but `String` is?
> "lo" <> "fa"
"lofa"
> 1 <> 2
Error found:
in module $PSCI
at :1:1 - 1:7 (line 1, column 1 - line 1, column 7)
No type class instance was found for
...
1
vote
0
answers
89
views
Why can't I use a row-polymorphic variable?
Take a look at this PureScript code:
type MyOtherProps = (value :: String)
type MyProps = (a :: String)
a
:: forall props phantom allProps
. Union MyProps MyOtherProps allProps
=> Union ...
1
vote
1
answer
279
views
Is there a way to integrate PureScript and Vite together?
I use spago to build src/Main.purs to output/Main/index.js.
I am trying to use Vite for the bundling tool and have successfully loaded output/Main/index.js in src/main.ts.
Vite can import image files, ...
2
votes
1
answer
129
views
Is `Pair` a valid instance of `MonadRec`?
In the paper Stack Safety for Free, Phil Freeman defines the MonadRec type class as follows.
class (Monad m) <= MonadRec m where
tailRecM :: forall a b. (a -> m (Either a b)) -> a -> m b
...
6
votes
2
answers
223
views
What is the name used in literature and libraries for the abstraction of "zero profunctors"
In real world application I noticed a pattern that could be generalized to something like:
purescript:
class Profunctor p <= Zero p where
pzero :: forall a b. p a b -- such that `forall f g. ...
1
vote
0
answers
100
views
spago docs only for project files
When I run spago docs, the documentation is generated for every dependencies in my project.
Is it possible to generate a documentation only for project files?
So only for .purs files in src.
I am ...
1
vote
2
answers
85
views
Purescript - iterate a longish array
The following code, being executed in Chrome, fails after printing 7492:
module Main where
import Prelude
import Effect (Effect)
import Effect.Console as Console
import Data.Array as Array
import ...
1
vote
1
answer
124
views
How to delete an element from an array using lenses
I'm trying to remove an element from an Array a using the index of the element but I can't find a way to do it with Lenses. I'm also wondering why Array does not provide an instance for the At lens. ...
0
votes
2
answers
157
views
vscode extension with a typed functional language
Is it possible to build a vscode extension from a javascript transpiler ? For example, is it possible to build an extension with "js of ocaml" or purescript. Those transpilers compiles to ...
4
votes
4
answers
287
views
Mapping functions over data in 'sum-types' in strongly typed programming languages
Today I encountered an implementation challenge with a large DU (sum-type) in F#, where I basically wanted to be able to map a set of functions over the values of the DU without having to repeat the ...
0
votes
0
answers
70
views
purescript: change element inside SVG
I have a SVG image like the following:
It is a simple SVG with a number in it. The SVG file looks something like this:
<svg ...>
<g ...>
<text id="my_text" ...>
...
0
votes
1
answer
43
views
Purescript Complex zero element (Purescipt by example exercies)
I solve Purescript exercise from the book https://book.purescript.org/chapter6.html#multi-parameter-type-classes
I don't understand what "zero" statement is?
I have "Complex" type, ...
1
vote
1
answer
113
views
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?
3
votes
1
answer
135
views
What is () defined as in Purescript? What does it mean?
What is () defined as? I see it in type signatures, I thought it was the unit type same as in Haskell but it seems instead Purescript uses Unit. So then what is ()?
Using spago repl was not helpful ...
3
votes
1
answer
88
views
Nested exhaustive pattern matching in Purescript
Consider my two attempts at writing the same function:
data Foo = Bar Int | Quux Int | Baz Int
f :: Foo -> Int
f (Bar n) = n
f other =
case other of
Quux n -> 2 * n
Baz n -> 3 * n
...
0
votes
0
answers
39
views
Adding Constraint Dynamically to a function
Is there any way I can add a constraint to a type class function dynamically?
Let's say my type class takes a function of type
type FieldTraverseFn :: Row Type -> (Type -> Type) -> Type
type ...
1
vote
1
answer
73
views
Why purescript can infer the Row.Cons contraint?
I have a newtype which takes a parameterized type,
newtype MockState m = MockState { apiState :: {api1 :: m Int, api2:: m String} }
derive instance newtypeMockState :: Newtype (MockState m) _
I have a ...
0
votes
1
answer
53
views
StateT monad inside Handler in purescript-express
I want to persist some data in StateT monad,
Within Handler of the post(any http method) function I want to modify the data stored in state... but the issue is I can't use State inside Handler...
...
0
votes
1
answer
100
views
`UnsafePartial` method works on non-partial function too - Purescript?
I'm trying to do something similar to what Partial type class does, so to understand Partial constraint better I started experimenting with it...
I created a normal function,
goodFn :: Int -> ...
0
votes
1
answer
82
views
Write Genric function that takes function signature of varying length of argument as argument in type level
I want to create a function, that takes function as varying argument, the only thing i know about the funtion argument(which is a function itself) is they are wrapped in the same Monad....
myFunc :: ...
2
votes
0
answers
50
views
Is there a way to refer to the result of the previous command in PSCi?
Coming from Haskell, I'm accustomed to using it to refer to the result of the previous command in GHCi:
ghci> 1+1
2
ghci> :type it
it :: Num a => a
ghci> it*2
4
I went looking to see if ...
3
votes
0
answers
150
views
Webpack Code Spliting increases the overall bundle size by 300%
For explaining this issue. I have created a sample project.
I am using purescript. I am doing a dynamic import and webpack is generating 2 bundles.
If I comment the dynamic import and use a static ...
0
votes
1
answer
53
views
How do composition and currying interact?
While doing exercises of chapter 3 of the Purescript by Example book was puzzled by this:
The exercise is to write an isInBook :: String -> String -> AddressBook -> Boolean
findEntryByName :: ...
0
votes
1
answer
106
views
How to implement fold right for Tree in purescript
I am new to Purescript so I was trying to implement fold left and fold right (aka reduce) for my custom Tree data structure, but I am having problem implementing logic for fold right:
data Tree a = ...
0
votes
1
answer
95
views
Which is a more efficient version of "takeEnd" function
I am new to PureScript so I am re-creating some basic functions, and I wanted to recreate "takeEnd" function which takes specified number of elements from the end of the list.
Here is ...
0
votes
1
answer
137
views
Purescript: How to read a string from stdin and save it?
I'm quite new to Purescript and I am trying to process some user input (received from stdin) but my best approach is this one:
processInput :: String -> Effect Unit
processInput input = do
let
...
1
vote
2
answers
116
views
PureScript - Splitting Array of Positive and Negative Numbers into Tuple of 2 Arrays of Positive and Negative Numbers
I'm a newbie in PureScript now reading a book "Functional Programming Made Easier: A Step-by-Step Guide", but when I got to the section on Tuples, I realised that all that was presented ...
2
votes
1
answer
125
views
Usecase of Variants in Purescript/Haskell
Can someone tell me what is the use case of purescript-variants or variants in general
The documentation is very well written but I can't find any real use case scenario for it. Can someone tell how ...
0
votes
2
answers
212
views
PureScript Error: Could not match kind Type -> Type with kind Type
I'm a newbie at PureScript trying out some code at this link. I've pasted the code here:
module Main where
import Prelude
import Data.Foldable (fold)
import Data.Tuple
import Data.Map as Map
import ...
1
vote
1
answer
121
views
purescript halogen - render elements or nothing conditionally
I have a utility function to conditinally render elements:
thanRender :: ∀ w i. Boolean -> EL.HTML w i -> EL.HTML w i
thanRender true h = h
thanRender _ _ = EL.text ""
Usage:
...
0
votes
2
answers
114
views
purescript data as array of all possible data inhabitants
I got the following data type:
data Icon = IconCircle | IconSquare | IconStar
I need an array of all possible Icons?:
allPossible :: Array Icon
allPossible = [IconCircle, IconSquare, IconStar]
Is ...
0
votes
0
answers
134
views
Is there type system with subtype relation that support exclusive struct field?
TLDR:
Is there a type system which allows we to express a type (constraint/interface) I = NoField<'a'>, such that for all type T, if T <: I, then T is a struct and does not have a specific ...
0
votes
1
answer
180
views
Can I always replace do ... pure ... with ado ... in ... in Purescript?
Can I always replace a do-block like this:
do
...
pure ...
where the last line is "pure" something,
with an ado-block like this:
ado
...
in ...
?
I know do only requires Bind and ...
1
vote
1
answer
138
views
How to chain actions in purescript (or maybe defer action after rendering)
I'm learning Halogen at the moment but I have a hard time finding how to chain actions. Let's say I have a simple article list component. I also have an "add" button to create a new article ...
0
votes
1
answer
67
views
Ascii color prefixes in PureScript doesn't work
I want to colorize my string with ASCII colors, but the following code...
data Color = White | Red | Green | Yellow
colorizeWith :: Color -> String -> String
colorizeWith Green s = "\031[...
0
votes
0
answers
82
views
Await with timeout using purescript-pipes
I'm trying to use a combination of purescript-pipes, and purescript-pipes-aff to write a version of await which will return Nothing if it doesn't receive a value in a specified amount of time.
So far, ...
0
votes
1
answer
69
views
PureScript. Argument list lengths differ in declaration
import Prelude
data Line = Front | Middle | Back
derive instance eqLine :: Eq Line
instance ordLine :: Ord Line where
compare a b | a == b = EQ
compare Front _ = LT
compare Back _ = GT
...
0
votes
0
answers
36
views
How to convert a Record to a Page that contains that Record with purescript
I have this function that returns
listScheduledPhotos :: ListScheduledPhotosOptions -> ExceptT Error Aff S3ObjectCollection
listScheduledPhotos = resolvePromiseOrThrow <<< ...
1
vote
2
answers
246
views
how to get string from stdin using Purescript?
as title says, I want to know about how to get stdin using Purescript.
I want to input string using my keyboard. that's all.
in fact, I can find some code just googling this. but nothing runs corretly....