## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
unclechu
@unclechu:matrix.org
[m]
vlj (vlj):
computeLinkedData :: Map Int MeasuredTask -> Map Int MeasuredTask
where
let
linkedTasksFromMap = catMaybes $(\x -> lookup x old) <$> view _uid <$> realMt.linkedTasks s = sum$ (\x -> view _cpuThread x) <$> linkedTasksFromMap in Just$ (over _cpuLinked ((+) s)) <<< (set _linkedTasks linkedTasksFromMap) $task propagateLink old (MeasuredTask mt) = let mtId = mt.uid partlyUpdatedMap = foldl propagateLink old mt.linkedTasks in update (updateTask partlyUpdatedMap) mtId partlyUpdatedMap but you can always use where section again: vlj (vlj): computeLinkedData :: Map Int MeasuredTask -> Map Int MeasuredTask computeLinkedData map = foldl propagateLink map map where updateTask old task@(MeasuredTask realMt) = Just$ (over _cpuLinked ((+) s)) <<< (set _linkedTasks linkedTasksFromMap) $task where linkedTasksFromMap = catMaybes$ (\x -> lookup x old) <$> view _uid <$> realMt.linkedTasks
s = sum $(\x -> view _cpuThread x) <$> linkedTasksFromMap
where
mtId = mt.uid
partlyUpdatedMap = foldl propagateLink old mt.linkedTasks
vlj
@vlj
ho didn't know where could be reused
unclechu
@unclechu:matrix.org
[m]
vlj
@vlj
ok
vlj
@vlj
thank you for the hint, I didn't know I could put several definition in a let... in clauses
vlj
@vlj
is it possible to put "assert" ?
unclechu
@unclechu:matrix.org
[m]
@vlj: i’d try to search in pursuit.purescript.org first whenever i think of something
vlj
@vlj
what is the "idiomatic" way to set up a purescript project ? I called pulp init and it created some file hiearchy, I use bower for dependency management, but it looks like psc-package is now the formal way to do
and there is also spago
and spago is a bit broken with powershell, it always open a new shell
Thomas M. DuBuisson
@TomMD

Oh I like the question. Having not been anything of a PS user I tried to make lambdas with spago and PS. The end result is probably not idiomatic project setup:

1. use npm to install purescript, parcel, spago, serverless
2. spago init
3. Manually edit the spago.dhall to add dependencies
4. npm install dependencies (express)
5. Add external pacakges to packages.dhall (namely, aws-lambda-express)
7. Use spago bundle-app then parcel to produce a final package.

So yes, if someone has idiomatic comments I'd love them too. Thanks for asking @vlj.

unclechu
@unclechu:matrix.org
[m]
@vlj: an example i recently got from my colleague https://github.com/MasseR/modern-purescript
not sure how idiomatic it is but it works. it built on top of Nix. i don’t know anything about windows though
vlj
@vlj
thanks
I'm having an issue with the "direction" of lens composition

I have an object

data PerformanceAggregate = PerfAgg {
cpuSum :: Int,
timeSum :: Int,
timeMin :: Int,
timeMax :: Int,
count :: Int,
categories :: Array PerformanceAggregate}

I want to have a lens to the first item of the categories array. I have defined this lens :

_categories :: Lens.Lens' PerformanceAggregate (Array PerformanceAggregate)
_categories = Lens.lens (\(PerfAgg x) -> x.categories) (\(PerfAgg x) y -> PerfAgg $_ {categories = y} x) but when I tried to "view" it, purescript tells me it returns an Array of PerformanceAggregate and not a PerformanceAggregate vlj @vlj with the following code : getAggregate perfCollec (Just (TaskFilter _ _ _ true)) = Lens.view ((Lens.ix 0) <<< _categories)$ perfCollec
but it doesn't work either if I invert Lens.ix 0 and _categories

the error message is :

in module Profiling
at src\Profiling.purs:106:7 - 106:121 (line 106, column 7 - line 106, column 121)

Could not match type

PerformanceAggregate

with type

Array PerformanceAggregate

while checking that expression createPerformanceAggregate
has type t0

where t0 is an unknown type

in the former case and

in module Profiling
at src\Profiling.purs:109:75 - 109:87 (line 109, column 75 - line 109, column 87)

No type class instance was found for

Data.Monoid.Monoid PerformanceAggregate

while checking that type forall p. Wander p => p PerformanceAggregate PerformanceAggregate -> p PerformanceAggregate PerformanceAggregate
is at least as general as type Forget t0 t0 t1 -> Forget t0 t2 t3
while checking that expression _NestedInt 0
has type Forget t0 t0 t1 -> Forget t0 t2 t3

where t1 is an unknown type
t0 is an unknown type
t3 is an unknown type
t2 is an unknown type

in the later

vlj
@vlj
when I do (perfCollec ^. _categories ) ^. (Lens.ix 0) I get the same error message as the second one, seems like I need some class instance to traverse an array of a custom type
vlj
@vlj
another question : how can I use 64 bits integer in purescript ? I'm trying purescript-longs but it complains at runtime :
[info] Build succeeded.
throw err;
^

Error: Cannot find module 'long'
Require stack:
at require (internal/modules/cjs/helpers.js:88:18)
code: 'MODULE_NOT_FOUND',
requireStack: [
]
}
[error] Running failed; exit code: 1
vlj
@vlj
does VScode provide step by step debugging for purescript ? Since it's javascript based but I suspect the source to js mapping may be non trivial
vlj
@vlj
for some reason it looks like the issue I faced with lens/array is gone now, if I use preview
Keith Layne
@keithlayne
hey everyone, I remember a goofy alternative set of unicode/emoji for common functions like bind. Does that ring a bell for anyone? I can't seem to find it now and it's relevant to another conversation.
vlj
@vlj
Is Purescript ok to write parsers ? I'm trying to implement one, it has 254438 tokens to parse, I'm getting a FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory error
it's a standard parser using Alternative and a Parser Applicative
william behrens
@WilliamBehrens_gitlab
Is it possible to embed purescript in the html script tag kinda like how coffeescript can?
unclechu
@unclechu:matrix.org
[m]
@WilliamBehrens_gitlab: do you mean to compile it on-the-fly? not sure if it’s possible since the compiler is written in Haskell. maybe with something like ghcjs but i doubt anyone have tried.
i remember there were some ideas/proposal to rewrite purescript in purescript so that it can self-compile. and distributed as well naturally with npm or whatever.
this also could be used to embed the compiler itself to browser’s side
william behrens
@WilliamBehrens_gitlab
well if anyone knows anything then let me know(this is what I was talking about btw http://coffeescript.org/#scripts)
Neil Han
@neilhan
Hi, I am learning purescript. Having a question. How do you provide a restriction to a type value. For example, if I want to define MyADT that takes only value that is of Eq class
data MyADT a = Eq a => MyADT
Gabriel Lebec
@glebec

@neilhan this has been explored in Haskell and the prevailing wisdom is that it is a bad idea in practice (in fact, it is now disabled by default); I don't know PureScript as well as Haskell but it is entirely possible that PS doesn't allow it.

The thing to do instead is to put constraints on functions which use your types.

data MyADT a = MyADT a

useMyADT = ...
If you need a constraint for construction purposes, e.g. you are building a binary search tree using Ord (or the PS equivalent), you can make a smart constructor that includes the constraint, and export that instead of the datatype's own raw constructors.