Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    vlj
    @vlj
    thanks
    unclechu
    @unclechu:matrix.org
    [m]
    @vlj: by the way, look at this module, it may really help to do functor-like stuff for newtypes with kind of just Type https://pursuit.purescript.org/packages/purescript-newtype/3.0.0/docs/Data.Newtype#t:Newtype
    for instance:
    newtype Label = Label String
    derive instance newtypeLabel :: Newtype Label _
    
    toUpperLabel :: Label -> Label
    toUpperLabel = over Label String.toUpper
    vlj
    @vlj
    ok
    btw it's not possible to make tuple like in Haskell ? For instance type XYZ = (Int, String)
    unclechu
    @unclechu:matrix.org
    [m]
    @vlj: I think there is no special syntax for tuples in PureScript. in Haskell there is just a bunch of syntactic sugar for regular data-types: https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Tuple.html#t:-40--44--44--44--44--44--44--41-
    vlj
    @vlj
    ok
    unclechu
    @unclechu:matrix.org
    [m]
    you can define them by yourself if you really need it
    vlj
    @vlj

    I'm trying to build a state monad but I get a RangeError due to maximum call stack size exceeded, my code is :

    
    type ProcessEventContext = Tuple (Map Int MeasuredTask) (Int)
    
    processStartEvent :: StartEvent -> State (ProcessEventContext) (Map Int MeasuredTask)
    processStartEvent s = do
      state <- get
      let map = fst state
      let stack = snd state
      pure $ map
    
    processStopEvent :: EndEvent -> State (ProcessEventContext) (Map Int MeasuredTask)
    processStopEvent s = do
      state <- get
      let map = fst state
      let stack = snd state
      pure $ map
    
    processTickEvent :: TickEvent -> State (ProcessEventContext) (Map Int MeasuredTask)
    processTickEvent s = do
      state <- get
      let map = fst state
      let stack = snd state
      pure $ map
    
    processDoNothing :: State (ProcessEventContext) (Map Int MeasuredTask)
    processDoNothing = do
      state <- get
      let map = fst state
      let stack = snd state
      pure $ map
    
    
    updateMap old (Start s) = processStartEvent s
    updateMap old (Stop s) = processStopEvent s
    updateMap old (Tick s) = processTickEvent s
    updateMap old (_) = processDoNothing
    
    eventToTaskM :: Array Event -> State (ProcessEventContext) (Map Int MeasuredTask)
    eventToTaskM list = do
        _ <- foldM updateMap empty list
        result <- get
        pure $ fst result
    
    
    eventToTask :: Array Event -> Map Int MeasuredTask
    eventToTask list =
      fst $ runState (eventToTaskM list) (Tuple empty 0)

    Is there a way to circumvent the issue ? I suspect it's due to foldM (the list has 100000s events)

    vlj
    @vlj

    actually I'm struggling with something else entirely, the state monad doesn't do what I'm expecting it do to. Here is the code :

    type ProcessEventContext = Tuple (Map Int MeasuredTask) (Int)
    
    processStartEvent :: StartEvent -> State (ProcessEventContext) Unit
    processStartEvent s = do
      old <- gets fst
      stack <- gets snd
      let updatedMap = (insert (s.iD) (createStartInfo s) old)
      put $ Tuple updatedMap stack
    
    processStopEvent :: EndEvent -> State (ProcessEventContext) Unit
    processStopEvent s = do
      state <- get
      let old = fst state
      let stack = snd state
      let updatedMap = update (changeTask s) s.taskStartId old
      put $ Tuple updatedMap stack
    
    
    processDoNothing :: State (ProcessEventContext) Unit
    processDoNothing = do
      pure unit
    
    updateMap (Start s) = processStartEvent s
    updateMap (Stop s) = processStopEvent s
    updateMap (Tick s) = processDoNothing
    updateMap (_) = processDoNothing
    
    eventToTaskM :: Array Event -> State (ProcessEventContext) (Map Int MeasuredTask)
    eventToTaskM arr = do
        let filtered = \x -> case x of Tick _ -> false
                                       _ -> true
        let filteredEvents = (take 1000 $ filter filtered arr :: Array Event)
        _ <- sequence_ $ updateMap <$> filteredEvents
        result <- get
        pure $ fst result
    
    
    eventToTask :: Array Event -> Map Int MeasuredTask
    eventToTask list =
      evalState (eventToTaskM list) (Tuple empty 0)

    But I always end up with a single item in the map. It looks like the squence is discarding the state

    vlj
    @vlj
    state don't connect ?
    vlj
    @vlj
    nvm I put the wrong input file
    vlj
    @vlj
    seems like some monad have stack safety but not the state monad
    unclechu
    @unclechu:matrix.org
    [m]
    @vlj: it’s javascript that’s has this stack limitation
    it can’t just take tail recursion and go okay with it
    i remember i had to use some folds instead of function recusion in order to overcome this
    you can always write some FFI with a loop inside or something
    vlj
    @vlj
    I found out that purescript-safely provide a traverse_ operator
    unclechu
    @unclechu:matrix.org
    [m]
    i mean you can implement your own fold or whatever traversing function that would use just plain loop
    vlj
    @vlj
    Is there a way to introduce several let ...= .. in in a row ?
    I have something like 3 or 4 definitions and the identation look strange
    unclechu
    @unclechu:matrix.org
    [m]
    @vlj: could you show an example what is the problem?
    vlj
    @vlj
    computeLinkedData :: Map Int MeasuredTask -> Map Int MeasuredTask
    computeLinkedData map =
      foldl propagateLink map map
      where
        updateTask old task@(MeasuredTask realMt) =
          let linkedTasksFromMap = catMaybes $ (\x -> lookup x old) <$> view _uid <$> realMt.linkedTasks in
            let s = sum $ (\x -> view _cpuThread x) <$> linkedTasksFromMap in
              Just $ (over _cpuLinked ((+) s)) <<< (set _linkedTasks linkedTasksFromMap) $ task
        propagateLink old (MeasuredTask mt) =
          let mtId = mt.uid in
            let partlyUpdatedMap = foldl propagateLink old mt.linkedTasks in
              update (updateTask partlyUpdatedMap) mtId partlyUpdatedMap
    I added an "update task" function it wasn't there initially
    btw what is the "debug" workflow in purescript ? Since purescript and Haskell doesn't allow to print something arbitrary this means I can't print value for debug purpose, in Haskell I think the lazy execution model is making debugging difficult but purescript use a "classic" execution model so it should be possible to inspect variable content ? In my case linkedTasksFromMap
    unclechu
    @unclechu:matrix.org
    [m]
    vlj (vlj):
    computeLinkedData :: Map Int MeasuredTask -> Map Int MeasuredTask
    computeLinkedData map =
      foldl propagateLink map map
      where
        updateTask old task@(MeasuredTask realMt) =
          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
        propagateLink old (MeasuredTask mt) =
          update (updateTask partlyUpdatedMap) mtId partlyUpdatedMap
          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: in Haskell too
    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" ?
    @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)
    6. Write your code
    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
    in binding group updatePerformanceCollectionWithTask
    
    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
    in binding group updatePerformanceCollectionWithTask
    
    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.
    internal/modules/cjs/loader.js:883
      throw err;
      ^
    
    Error: Cannot find module 'long'
    Require stack:
    - C:\Users\vljno\Source\Repos\pursssscript\output\Data.Long.Internal\foreign.js
    - C:\Users\vljno\Source\Repos\pursssscript\output\Data.Long.Internal\index.js
    - C:\Users\vljno\Source\Repos\pursssscript\output\Data.Long\index.js
    - C:\Users\vljno\Source\Repos\pursssscript\output\ParseEvents\index.js
    - C:\Users\vljno\Source\Repos\pursssscript\output\Main\index.js
    - C:\Users\vljno\Source\Repos\pursssscript\.spago\run.js
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
        at Function.Module._load (internal/modules/cjs/loader.js:725:27)
        at Module.require (internal/modules/cjs/loader.js:952:19)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (C:\Users\vljno\Source\Repos\pursssscript\output\Data.Long.Internal\foreign.js:5:12)
        at Module._compile (internal/modules/cjs/loader.js:1063:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
        at Module.load (internal/modules/cjs/loader.js:928:32)
        at Function.Module._load (internal/modules/cjs/loader.js:769:14)
        at Module.require (internal/modules/cjs/loader.js:952:19) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\output\\Data.Long.Internal\\foreign.js',
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\output\\Data.Long.Internal\\index.js',
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\output\\Data.Long\\index.js',
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\output\\ParseEvents\\index.js',
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\output\\Main\\index.js',
        'C:\\Users\\vljno\\Source\\Repos\\pursssscript\\.spago\\run.js'
      ]
    }
    [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.