Conversation started Feb 25, 2015 at 10:23.
Feb 25, 2015 10:23
is Benji around?
@BartekBanachewicz only sorta - why?
@BenjaminGruenbaum is there a name for a relation between two higher-kinded types when A (B x) can be viewed as equivalent to B (A x)?
ffs sorry for the plinks. I'm terrible with this chat thing.
A and B are functions?
nah, kinds
like Maybe
For example...
Maybe [a] and [Maybe a] is what I'm thinking about
in this case, it's clearly different in what order you apply the wrapping types
You mean that composing types in different order gives the same result? That the order is not important?
Feb 25, 2015 10:26
but in some others, I think it might be not relevant
@BenjaminGruenbaum precisely
Sounds like associativity
lel
I'm dumb nvm.
@BartekBanachewicz wait, it's not, it's commutativity
well, either of the basic operations, was my point, and I wasn't thinking in terms of those
Since you want A op B to be the same as B op A
Feb 25, 2015 10:28
yea
Then yes, we say that composition is commutative for types A and B
time to google for commutative types
woo letters and arrows that means I'm on the right path :D
I don't think Haskell's type system can express those though :P
It's actually a classic problem in many areas and a classic exercise in dynamic programming
Given n commutative and associative operations find the optimal order for applying them.
Feb 25, 2015 10:32
@BenjaminGruenbaum mmm
It's classic in graphics (multiplying several matrices in a row), in databases (performing n joins) and so on.
Well what I had in mind was something related to an answer I just wrote
You have a Report type. It can be either a Failure or Success, and either XML or JSON
of course you can just write Report = Report Outcome Type
but what if you could actually compose FailureOrSuccess and that type
data MaybeFailing a = Fail a | Success a
data ContentType a = XML a | JSON a

type Report a = MaybeFailing (ContentType a) -- ~ ContentType (MaybeFailing a)
aaaand then in pattern matches, you can unwrap either layer
@BartekBanachewicz I wouldn't do it like that, I'd write a specific data type rather than a composable one since I think it'd give much more information. Like a Fail | JSON | XML or something like that.
v :: Report

case v of
    Failure x -> -- x :: ContentType a

case v of
    XML y -> -- y :: MaybeFailing a
I've found developers to be enjoying those a lot more.
Feb 25, 2015 10:38
@BenjaminGruenbaum the point was you can either succeed or fail with either xml or json report
combinatorial explosion
@BartekBanachewicz You can fail with JSON?
You can succeed with XML?
@BenjaminGruenbaum well, giving a failure report in JSON, I mean
@copy hihih
Well, good luck. I have to go work on my robot. TTYL.
I just think the fact that you could unwrap two such commutative layers in an arbitrary order is interesting
 
Conversation ended Feb 25, 2015 at 10:40.