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
    actually no it's the same
    unclechu
    @unclechu:matrix.org
    [m]
    @vlj: i think you can derive it: derive instance functorMeasuredTask :: Functor MeasuredTask
    @vlj: btw, you can replace data with newtype for MeasuredTask since it wraps only one single value
    ah, i’m wrong about the functor
    @vlj: you should either use something like Functor1 or destructure MeasuredTask
    damn, i don’t think any functor would work here 😅
    MeasuredMask don’t have any type argument to map
    vlj
    @vlj
    yes
    unclechu
    @unclechu:matrix.org
    [m]
    changeTask :: EndEvent -> MeasuredTask -> Maybe MeasuredTask
    changeTask s (MeasuredTask task) =
      Just $ MeasuredTask $ task { timeEnd = s.time, cpuEnd = s.cpuTicks, cpuThread = task.cpuThread + s.cpuTicks }
    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