## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
@techla
Klisli arrows are just like haskell ones
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
@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
@techla
@Daenyth here is the full implementation I work on
Gavin Bisesi
@Daenyth
anyway gtg shortly but I hope that helps
@techla
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
@techla
I’m trying to clean, optimize it and make it works with those two last functions
@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
@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
@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
@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.
@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
@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