Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Foad Ardalan
    @techla
    can It help here ?
    Gavin Bisesi
    @Daenyth
    String -> Parser (Array Char) is ~= Kleisli Parser String (Array Char), so map on that gets you to Kleisli Parser String String
    I don't know enough of ps/haskell to give the most succinct way to do that
    Foad Ardalan
    @techla
    ok I will think about it.
    i need some minutes to wrap my mind around what you've just said
    Gavin Bisesi
    @Daenyth
    I'll try a tldr

    FP is all about composition - how to combine expressions to larger ones that mean what you want.

    Mathematical functions are like A => B and then compose really nicely, A=>B and B=>C compose to give you A => C

    Category theory is the study of composition, generalizes that notion of composition. It notices that a -> f b shaped functions can still compose for some f - Monads. a -> f b and b -> f c give you a -> f c - that's flatMap/bind/>>=/whatever you call it

    The "Kleisli" category is the name for the category of composition on that shape.

    Kleisli types, aka "reader monad" or ReaderT more generally, are how we encode that in FP languages.

    Where a -> b is a monad mapping on b, if you tried using that -> monad for a -> f b you'd be mapping on f b, not b. Kleisli/ReaderT shapes let you change the monad being used so that given shapes like a -> f b, you map on the b

    So since String -> Parser (Array Char) is such a shape / a=String f=Parser b=Array Char, then you can use Kleisli/ReaderT to recover the ability to map on the Array Char part, which is exactly the operation you want
    Foad Ardalan
    @techla
    @Daenyth here is the full implementation I work on
    Gavin Bisesi
    @Daenyth
    anyway gtg shortly but I hope that helps
    it compiles
    and it works modulo the jsonArray and the jsonObject
    Gavin Bisesi
    @Daenyth
    there we go, Control.Monad.Reader.Trans is the place to look for that shape
    It's called ReaderT in ps. I'm used to scala where the newtype is called Kleisli and ReaderT is just an alias for it
    Foad Ardalan
    @techla
    I’m trying to clean, optimize it and make it works with those two last functions
    ReaderT is the Reader Transformer if I don’t get it wrong
    it’s for monad composition
    Foad Ardalan
    @techla
    @Daenyth thank you for your help
    I have a little category theory background and I really want to make it work with it
    I will explore the solution you presented to me
    thank you again
    Gavin Bisesi
    @Daenyth
    on the other hand though it's just one line of code, might not be worth it unless this is a widespread thing
    Foad Ardalan
    @techla
    it’s a good exercise anyway
    Gavin Bisesi
    @Daenyth
    Writing naive and straightforward code is often best unless you're sure the fancy stuff pays off enough for how much it costs other developers to read
    Foad Ardalan
    @techla
    @Daenyth it’s actulally as simple as stringP :: String -> Parser String stringP = (map (fromCharArray)) <<< sequence <<< (map charP) <<< toCharArray :D
    I get it wrong since the very begining
    Sean Yu
    @seanyu4296
    @techla afaik, Show instances are not derivable. What you can do is derive instance generic then use genericShow
    import Data.Generic.Rep as GR
    import Data.Generic.Rep.Show (genericShow)
    
    data IntOrBoolean2
      = Int2 Int
      | Boolean2 Boolean
    
    -- note the underscore at the end for the `rep` parameter of class Generic
    derive instance genericIntOrBoolean2 :: GR.Generic IntOrBoolean2 _
    
    instance showIntOrBoolean2 :: Show IntOrBoolean2 where
      show = genericShow
      -- now we get a Show
    Foad Ardalan
    @techla
    @seanyu4296 thank you
    here the Rep stands for Representable ?
    ie Functors that are isomorphique to the Home Functor ?
    Sean Yu
    @seanyu4296
    I think so Rep is representable
    a is representable in this kind of data structure
    ohhh im not sure about the second question.
    Foad Ardalan
    @techla
    Representable in category theory are those Functors
    the Rep keyword in haskell meens that
    @seanyu4296 it’s a type class that defines 2 functions tabulate and index
    Sean Yu
    @seanyu4296
    ahh no i think it is different. im not well versed with category theory
    Foad Ardalan
    @techla
    Stream are representable (List minus the empty List)
    so what does Rep represent ?
    in category theory those functors that you can tabulate or index can « represent » the home functor
    tabulate and index are actually 2 natural transformations going back and forth to the Home functor
    Foad Ardalan
    @techla
    (understood that the Home Functor is the Reader Functor)
    Sean Yu
    @seanyu4296
    from what i know under the hood if you derive an instance of Generic
    rep is a Sum, Product,Constructor, NoConstructor, Arguments, NoArguments
    Ill get back to you next time on the functors and category theory since im not familiar yet
    Foad Ardalan
    @techla
    Clear and accessible