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
    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.
    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 :: Eq x => MyADT x -> Bool
    useMyADT = ...
    Technically this means you can create data which doesn't have the constraints you want, but it doesn't matter, because the moment you'd try to use the functions that do anything useful, the typechecker would complain and refuse to compile anyway; so in reality you end up never constructing "useless" data.
    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.
    Neil Han
    @neilhan
    Thank you, Gabriel. Your reply is very helpful.