Skip to content

Instantly share code, notes, and snippets.

@imeredith
Created January 18, 2012 00:05
Show Gist options
  • Save imeredith/1629914 to your computer and use it in GitHub Desktop.
Save imeredith/1629914 to your computer and use it in GitHub Desktop.
cyth has left IRC (Quit: Ex-Chat)
dobblego
jamil_1: those laws are: associativity and an identity object
jamil_1
dobblego: right
dobblego
let's write this
dobblego
although I'll probably fuck it, as per my usual writing code in a IRC client
dobblego
! trait Category[~>[_, _]] { def compose[A, B, C](f: B ~> C)(g: A ~> B): A ~> C; def id[A]: A ~> A }
multibot_
defined trait Category
dobblego
yay
dobblego
so roughly, a category is "anything that implements that trait"
jamil_1
right
dobblego
think you can implement it with something?
dobblego
there's a *really* obvious one
jamil_1
posets, functions
dobblego
zing
jamil_1
see! I am learning :)
dobblego
Function1
dobblego
do you know what a lens is?
jamil_1
I have a rough idea
jamil_1
getters and setters
dobblego
I'll show you
jkriesten has left IRC (Read error: Connection reset by peer)
dobblego
case class Lens[A, B](get: A => B, set: (A, B) => A))
dobblego
right?
jkriesten has joined ([email protected])
jamil_1
right
dobblego
you know what's next don't you?
jamil_1
nope
dobblego
Lens is a category!
jamil_1
hmm
dobblego
val LensCategory: Category[Lens] = ... yes, there is an answer here
dobblego
this means we can compose lenses!
jamil_1
awesome
dobblego
you know, a Person has an Address and an Address has a Street
dobblego
that means a Person has a Street
dobblego
and we can set it easily!
dobblego
it's almost as if category theory is practical to everyday programming or something!
dobblego
there are other categories
dobblego
another is Monad[F] => Kleisli[_, F, _]
Arrgh
casualjim, oh hi
dobblego
case class Kleisli[A, F[_], B](k: A => F[B])
dobblego
ok, so an Arrow is a type of category
dobblego
it has additional constraints on its "trait"
dobblego
so all things which are arrows must first be categories *plus* satisfy the arrow constraints
casualjim
Arrgh: Hey
jamil_1
true
Arrgh
casualjim, nothing to say, I was just wondering if ivan___ was you
jamil_1
dobblego: so Kleisli is a category of Arrows ?
dobblego
trait Arrow[~>[_, _]] { def arr[A, B](f: A => B): A ~> B; def first[A, B, C](f: A ~> B): ((A, C) ~> (B, C))
dobblego
Monad[F] => Kleisli[_, F, _] is a category, is it an arrow?
dobblego
oh I forgot
dobblego
trait Arrow[~>[_, _]] extends Category[~>] { def arr[A, B](f: A => B): A ~> B; def first[A, B, C](f: A ~> B): ((A, C) ~> (B, C)) } // forgot extends Category
jamil_1
?
dobblego
plus some laws and shit
twittard has joined ([email protected])
dobblego
so the question is, we know that e.g. Function1 is a category (why that's easy, since compose is function composition and id is the identity function)
dobblego
but is it also an arrow?
dobblego
can it satisfy that interface?
dobblego
YES!
dobblego
and what about Monad[F] => Kleisli[_, F, _] ?
dobblego
YES AGAIN!
dobblego
and Lens?
lopex has left IRC (Read error: Connection reset by peer)
jrwest has left IRC (Read error: Connection reset by peer)
tomh has left IRC (Remote host closed the connection)
dobblego
No, Booooo
ivan___
where can i find a doc that explains what ~> does ? one major issue i have with scala is finding what symbols mean (generally for the type system)
dobblego
ivan___: it's a variable that I declared, I just named it that
ivan___
oh
lopex has joined (u4272@gateway/web/irccloud.com/x-qsogiskylmyuiiff)
ousado has left IRC (Read error: Connection reset by peer)
ivan___
dobblego: oh trait a [~>[_,_]] is like trait a[T[_,_]] or something
ivan___
?
jamil_1
ivan___: yes, ~> is a type variable
datura
http://symbolhound.com/ http://scalex.org/
datura
ivan___: sometimes useful to find this kind of names
ivan___
in terms of (f: A => B): A ~> B , what and how is ~> working?
pantsman
ivan___, same as (f: A => B): ~>[A, B]
nomadmonad has left IRC (Quit: nomadmonad)
ivan___
oh
ivan___
right
pantsman
consisting of non-alpha chars means you can use infix notation
pantsman
(I think)
tomh has joined (u501@gateway/web/irccloud.com/x-blzsxyzimldshmdh)
dobblego
ivan___: yes I just prefer a name that I can use in infix
MarkMenard has left IRC (Quit: MarkMenard)
szeiger_ has left IRC (Quit: Leaving)
ivan___
dobblego: the type system is probably my biggest problem with scala learning atm... i tend to just glaze over...
dobblego
ivan___: declare trait Category, now implement it for Function1, then Lens
dobblego
now use it
dobblego
it's a 30 minute exercise
dobblego
but then, take a break, come back and do it again, think about it in between
ivan___
ill save this convo and do it later, and get back to you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment