Skip to content

Instantly share code, notes, and snippets.

View larsrh's full-sized avatar
🏝️
On hiatus.

Lars Hupel larsrh

🏝️
On hiatus.
View GitHub Profile
@larsrh
larsrh / optics.scala
Last active July 24, 2016 16:16 — forked from julien-truffaut/optics.scala
Attempt to get single compose method between optics
package vanilla
sealed trait Optic[G[_,_] <: Optic[G, _, _], S, A] {
def compose[F[_, _] <: Optic[F, _, _], B](o: F[A, B])(implicit lub : Lub[G,F]) : lub.T[S, B] =
lub.compose(self, o)
def self: G[S,A]
def desc: List[String]
}
case class Traversal[A,B](desc : List[String]) extends Optic[Traversal,A,B] {
@larsrh
larsrh / Entities.hs
Last active January 2, 2016 06:58 — forked from anonymous/entities.hs
{-# LANGUAGE ExistentialQuantification #-}
module Entities where
data Point = TwoD Int Int | ThreeD Int Int Int
class Entity a where
pos :: a -> Point
speed :: a -> Int
id :: a -> String
// ------------------------------------------------------
// Combined List/Option/Either
// ------------------------------------------------------
object MonadTransformers extends App {
import scalaz._
import scalaz.std.option._
import scalaz.std.list._
type OptionTList[α] = OptionT[List, α]
@larsrh
larsrh / The Union Type Quiz
Last active December 19, 2015 09:59 — forked from soc/The Union Type Quiz
My answer to @soc's "union type quiz". To be taken with a grain of salt, I'm not even into type theory.
The Union Type Quiz
===================
1. Please describe the guiding principle of your typing approach in one sentence:
For ADTs, do not (in general) expose the cases as types.
import scalaz.std.anyVal._
import scalaz.std.tuple._
import scalaz.std.option._
import scalaz.StateT
import scalaz.State
import scalaz.Trampoline
import scalaz.syntax.traverse._
import scalaz.std.list._
import scalaz.Free
@larsrh
larsrh / RequestHeader.scala
Created September 19, 2012 21:43 — forked from bblfish/RequestHeader.scala
Claim Monad for X509 Certificates - having trouble running map on it
import java.net.URI
import scalaz.concurrent.Promise
import scalaz._
import Scalaz._
import language.implicitConversions
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] )
trait RequestHeader {
@larsrh
larsrh / gist:3240574
Created August 2, 2012 20:54 — forked from channingwalton/gist:3230464
Example of Kleisli composition of Either
object KleisliValidation extends App {
import scalaz._
import Scalaz._
import scala.util.control.Exception._
type EEither[+T] = Either[String, T]
def toDouble(s: String): EEither[Double] = allCatch.either(s.toDouble).fold(_.toString.left, _.right)
def sqrt(d: Double): EEither[Double] = if (d >= 0) math.sqrt(d).right else "sqrt(%s) is too complex for me".format(d).left