Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
@pedrofurla
pedrofurla / gist:6069867
Created July 24, 2013 11:50
Extending query builder with extract... it's currently H2Driver only.
package slickdemo.experiments
import scala.slick.driver.{BasicStatementBuilderComponent, H2Driver}
import scala.language.implicitConversions
/**
* Created with IntelliJ IDEA.
* User: pedrofurla
* Date: 18/07/13
* Time: 19:00
@pedrofurla
pedrofurla / gist:6147883
Last active December 20, 2015 14:39
Transforming a project setting
source:
lazy val sxr = scalaz.configure{
p =>
Project(
id=p.id+"-sxr",
base = file("."),
settings = p.settings ++
Seq(
addCompilerPlugin("org.scala-sbt.sxr" % "sxr_2.10" % "0.3.0-SNAPSHOT"),
@pedrofurla
pedrofurla / gist:6496611
Created September 9, 2013 14:46
"Subverting" Scala parser with compiler plugin
sealed trait Foo | Bleh | Dummy(val x:Int)
Into:
sealed trait Foo
case class Bleh extends Foo
case class Dummy(val x:Int) extends Foo
@pedrofurla
pedrofurla / gist:6497566
Created September 9, 2013 15:51
Showing the show off to S11001001
// Show the problem
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.setContentType("text/html")
resp.setCharacterEncoding("UTF-8")
// TROUBLE // TROUBLE // TROUBLE
var a:Int = req.getParameter("a").toInt
var b:Int = req.getParameter("b").toInt
var c:Int = req.getParameter("c").toInt
@pedrofurla
pedrofurla / Church.scala
Created September 13, 2013 01:45
Church encodings in Scala value level. Unfinished.I am not sure 'and' and 'or' could be better.
package fpis
/**
* User: pedrofurla
* Date: 11/09/13
* Time: 08:17
*/
object Church {
/*
@pedrofurla
pedrofurla / Reflect.scala
Created September 18, 2013 04:08
Guess work...
scala> ru.typeOf[Monad[List]]
res13: reflect.runtime.universe.Type = Monad[scala.List]
scala> res13.typeSymbol.typeSignature
res19: reflect.runtime.universe.Type = [F[_]]Applicative[F] with Bind[F]
scala> res13.typeSymbol.typeSignature.asInstanceOf[scala.reflect.internal.Types$PolyType]
res25: scala.reflect.internal.Types$PolyType = [F[_]]Applicative[F] with Bind[F]
scala> res25.parents
@pedrofurla
pedrofurla / Church.scala
Created September 18, 2013 09:35
Church
package fpis
/**
* User: pedrofurla
* Date: 11/09/13
* Time: 08:17
*/
object Church extends App {
/*
@pedrofurla
pedrofurla / gist:6690176
Created September 24, 2013 19:40
Numbers
type NUM[A] = (A => A) => A => A
def succ [A]: NUM[A] => NUM[A] = m => n => x => n(m(n)(x))
def plus [A]: (NUM[A]) => (NUM[A]) => NUM[A] = m => n => f => x => m(f)(n(f)(x))
def times [A]: (NUM[A]) => (NUM[A]) => NUM[A] = m => n => f => x => m(n(f))(x)
def isZero[A]: (NUM[A]) => BOOL[A] = m => a => b => m(_ => F[A](a)(b))(T[A](a)(b))
//
/*
pred ≡ λn.λf.λx. n (λg.λh. h (g f)) (λu. x) (λu. u)
SHIT: http://okmij.org/ftp/Computation/lambda-calc.html#predecessor
http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=70E6927502DB038ABB1DF6AD0390312F?doi=10.1.1.26.7908&rep=rep1&type=pdf
@pedrofurla
pedrofurla / gist:7307932
Last active December 27, 2015 09:59
Combinations
scala> List(1,2);
res12: List[Int] = List(1, 2)
scala> for(x <- res12) yield List(x)
res16: List[List[Int]] = List(List(1), List(2))
scala> for(x <- res12; y <- res12) yield List(x,y)
res13: List[List[Int]] = List(List(1, 1), List(1, 2), List(2, 1), List(2, 2))
scala> for(x <- res12; y <- res12; z <- res12) yield List(x,y,z)
@pedrofurla
pedrofurla / gist:8052119
Created December 20, 2013 08:49
Improvements?
class Misty m where
banana :: (a -> m b) -> m a -> m b
unicorn :: a -> m a
-- Exercise 6
-- Relative Difficulty: 3
-- (use banana and/or unicorn)
furry' :: (a -> b) -> m a -> m b
furry' f mm = banana (unicorn . f) mm