Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Thanks @Ebmtranceboy, Will try again with implementation of fold & folr.
    It is working fine when both foldl & foldr is implemented. Understood issue with 2d structure.
    Jun Matsushita
    Hi there, I'm bumping into a type error I can't make sense of when making a record of natural transformations. I've made a gist which I think is a minimal reproduction : https://try.purescript.org/?gist=404eefaba98d2e42c16fcd333487ce8b
    It works with a simple data constructor Nat m n = Nat (m ~> n) but not with a record NatR m n = Nat { nat :: (m ~> n) }
    Jun Matsushita
    use :: forall m n. Nat m n -> m Unit -> n Unit
    use (Nat nat) = nat 
    useR :: forall m n. NatR m n -> m Unit -> n Unit
    useR (NatR { nat }) = nat -- Error!
    I get an error with useR:
      Could not match type
      with type
    while trying to match type m0 a2
      with type m0 Unit
    while checking that expression nat
      has type m0 Unit -> n1 Unit
    in value declaration useR
    where n1 is a rigid type variable
            bound at (line 0, column 0 - line 0, column 0)
          m0 is a rigid type variable
            bound at (line 0, column 0 - line 0, column 0)
          a2 is a rigid type variable
            bound at (line 17, column 34 - line 17, column 54)
    Jun Matsushita

    Looks like something's up with inference and pattern matching record puns since using dot syntax type checks correctly:

    useR3 :: forall m n. NatR m n -> m Unit -> n Unit
    useR3 (NatR n) = n.nat

    Is that a bug or known behavior?

    @jmatsushita Sometimes, it is difficult to predict what the compiler complains about with polymorphic definitions. Often, it is sufficient to provide enough arguments : useR (NatR { nat }) x = nat x
    Jun Matsushita

    @Ebmtranceboy Thanks, neat trick! I had to extend my minimal example because unfortunately, in my case it still didn't work. https://try.purescript.org/?gist=c544c34971cecfd61528fa06c996460b

    data Nat m n = Nat (m ~> n)
    data NatR m n = NatR { nat :: (m ~> n) }
    morphS :: forall m n. Monad m => Monad n => (m ~> n) -> m Unit -> n Unit
    morphS t fm = t fm
    -- useR :: forall m n. Monad m => Monad n =>  NatR m n -> m Unit -> n Unit
    -- useR (NatR { nat }) x = morphS nat x -- Error!
    -- Error: Could not match type a4 with a1 
    --   a4 rigid type variable bound at line 17, column 34-54...
    -- Stays at line 17 even if I move the code around.
    -- Actually it's also the same location in my local code base... Wat?   
    useR' :: forall m n. Monad m => Monad n =>  NatR m n -> m Unit -> n Unit
    useR' (NatR h) x = morphS h.nat x -- Works
    useR'' :: forall m n. Monad m => Monad n =>  NatR m n -> m Unit -> n Unit
    useR'' (NatR h) = morphS h.nat -- Pointfree also works

    There's also some added strangeness going on with the code location reported by the type checker... Should some of this be documented as gotchas somewhere so that they're googleable?

    @jmatsushita I'm not sure where is heading your investigations. The compiler error you mention goes away if you replace morphS with identity in the useR definition but you probably have something else in mind :) I advise you to ask on the functional programming Slack, channel #purescript or #purescript-beginners. They're quite crowded
    Jun Matsushita
    Thanks @Ebmtranceboy I'll head there!
    Kevin Mungai
    Screenshot from 2020-07-06 21-06-18.png
    Hi everyone hope you are well. How do I import Nothing from Data.Maybe I am getting an error as shown above
    Jun Matsushita
    You probably want to import Data.Maybe (Maybe(..))
    The (..) asks to not only import the type, but also the type constructors (Just and Nothing)
    Kevin Mungai
    Thanks I will use (..) to import the type constructors as well.
    Ketan Shukla
    Are there any courses out there that teaches purescript with react?

    I have a type system question.

    I can express head as a natural transformation like so:

    head' ∷ List ~> Maybe
    head' = head

    My intuition is that join is also a natural transformation of the type forall m. m m ~> m

    But if the kind of m :: Type -> Type then m m won't compile because the kind of the type argument to the outer m is type -> type and it expects the kind type

    join' ∷ forall (m :: TypeType) . Bind m ⇒ m m ~> m
    join' = join
      join' ∷ forall (m :: TypeType) . Bind m ⇒ m m ~> m
      Could not match kind
      with kind
        Type -> Type

    I also tried using a type lambda there to get the the type of the inner m to be correct

      43  join'' ∷ forall (m :: Type → Type) . Bind m(∀ a. a → m (m a)) ~> m
      Could not match kind
        Type -> Type
      with kind

    Which results in a different type error. Which I am very confused by, the compiler seems to be expect the underlined section to have the kind type but I would expect that it should be type -> type because it's on the left of ~>

    Does anyone know how I can express join as NaturalTransformation or am I just completely lost.

    @jangoolie There is a confusion between m m aand m (m a)
    type M2 m a = m (m a)
    join' :: forall m. Bind m => M2 m ~> m
    join' = join

    isn't that what I addressed with my type lambda approach:

    join'' ∷ forall (m :: Type → Type) . Bind m ⇒ (∀ a. a → m (m a)) ~> m

    @jangoolie sure, but now it feels like a syntactic problem and I'm not really sure what you should do. Maybe ask the slack/discord channels
    Yilin Wei
    @jangoolie , I might be being a bit obtuse, but how does purescript know that's a type lamda and not a universally quantified function?
    (never seen that syntax before)
    hey, I get dep conflicts while trying to install zephyr 0.3.2, anyone tried it?
    John Winston
    Hi guys, is there any Ramda equivalent in Purescript? I guess functions like pipe() and compose() is quite common and someone must have made it before?
    module Main where
    import Data.Array
    import Data.Array.ST
    import Effect.Ref
    import Prelude
    import Control.Monad.ST.Internal
    import Control.Monad.ST (run, for)
    import Control.Monad.ST.Ref as Ref
    import Effect (Effect, forE)
    import Effect.Class.Console (log, logShow)
    import Data.Maybe (Maybe(..), fromMaybe)
    import Partial.Unsafe (unsafePartial)
    main :: Effect Unit
    main = void $ unsafePartial do
      let nodes = [
               [-100.0, -100.0, -100.0],
               [-100.0, -100.0,  100.0],
               [-100.0,  100.0, -100.0],
               [-100.0,  100.0,  100.0],
               [ 100.0, -100.0, -100.0],
               [ 100.0, -100.0,  100.0],
               [ 100.0,  100.0, -100.0],
               [ 100.0,  100.0,  100.0]
      ref <- empty
      void $ forE 0 8 $ \i ->  do
        let xx = (nodes !! i)
        let yy = fromMaybe [] xx
        void $ push yy ref
      log "x"
    here ref is mutable array on doing push yy ref it's throwing
      Could not match type
        ST t1
      with type
    while trying to match type t0 Unit
      with type Effect Unit
    while checking that expression (apply void) ((push yy) ref)
      has type Effect Unit
    in value declaration main
    where t0 is an unknown type
          t1 is an unknown type
    someone help me please
    Tomáš Markacz
    Hi there! I'm new to functional programming and PureScript. I was playing around with monoids and I'm curious:
    import Data.Monoid.Conj
    Conj false <> Conj true
    This returns me false „wrapped“ within Conj monoid, how can I get the Boolean out?
    Thomas M. DuBuisson
    The Conj constructor is probably exported, so just pattern match?
    let Conj result = Conj false <> Conj true
    Tomáš Markacz
    Thank you! So there's no function like getAny for Any monoid in Haskell, right?
    Thomas M. DuBuisson
    It appears not (see here https://github.com/purescript/purescript-prelude/blob/v4.1.1/src/Data/Monoid/Conj.purs#L15-L15). You could make a PR and see what the author thinks.
    Mat Fournier
    Hey. Besides the purescript book (which is great), where would someone go for the most braindead framework to start using? I haven't touched PS in two years but want to get back into it on some side projects / hackday stuff.
    Hey! just started with PS and with JS for that matter. Playing with a JS framework and studying FFI I stumbled onto a weird problem:
    first one works just fine, but second one produces a this ~ undefined problem
    Hooks.on uses this._hooks under the hood so I get an error: "Object._hooks is undefined". However I verified that the right function is found and executed. Does anyone know what can cause such behaviour?
    Kevin Esler
    What is the idiomatic way to convert a (Map Int String) to the corresponding List Int String ? I'm using Map.toUnfoldable myMap :: List Int String
    Hi, is there a good CSV parsing lib ? I'm using purescript-csv but on big csv file (20000 lines) I get "RangeError: Maximum call stack size exceeded"
    is there support for explicit type annotation ? In haskell there is "@" eg "@String" for instance for some function but it doesn't seem to work in purescript
    @vlj: in Haskell it’s TypeApplicatons extension which helps to annotate just type variables. regular type annotation is done like this: (func :: SomeTypeAnnotation) both in Haskell and PureScript
    there is no extension in purescript ?
    @vlj: i’m not even sure if there are any extensions in PureScript. every feature of the language in turned on already
    :point_up: Edit: @vlj: i’m not even sure if there are any extensions in PureScript. every feature of the language is turned on already

    I'm having some trouble with my record types.
    I have a type `

    data MeasuredTask = MeasuredTask {
        uid :: Int,
        threadId :: Int,
        linkedParentId :: Int,
        label :: String,
        nestedTasks :: Array MeasuredTask,
        linkedTasks :: Array MeasuredTask,
        timeStart :: String,
        timeEnd :: String,
        cpuStart :: Int,
        cpuEnd :: Int,
        cpuThread :: Int,
        cpuLinked :: Int,
        timeLinked :: Int,
        lineStart :: String,
        lineEnd :: String}

    It's not "just" a record because it 's inductively defined so I put a MeasuredTask constructor

    issue is that when I want to defined lens on it using profunctor-lens the

    _timeEnd :: forall a r. Lens' { timeEnd :: a | r} a
    _timeEnd = prop (SProxy :: SProxy "timeEnd")

    doesn't work on it, because well these lenses act on row polymorphic type