Skip to content

Instantly share code, notes, and snippets.

View gclaramunt's full-sized avatar

Gabriel Claramunt gclaramunt

View GitHub Profile
combinations:: String -> [String]
combinations [] = []
combinations (x:xs) = [x] : combs ++ fmap (x :) combs
where combs = combinations xs
def fun(k:Int)={
val x = f(k)
val y = g(x)
val z = h(y)
x+y+z
}
// If f,g,h return Option
def fun1(k:Int)=for {
@gclaramunt
gclaramunt / HList.hs
Created February 10, 2015 18:17
Heterogeneous list in Haskell
{-# LANGUAGE GADTs #-}
module HLists where
data Hlist where
HNil :: Hlist
HCons :: a-> Hlist -> Hlist
HConsShw :: Show a => a-> Hlist -> Hlist -- show here is horrible
instance Show Hlist
where show HNil = ""
show (HCons a l) = "?" ++ ","++ show l
@gclaramunt
gclaramunt / middle.hs
Created July 11, 2014 21:59
Middle of a list with the hare and tortoise method
-- | Main entry point to the application.
module Main where
-- | The main entry point.
main :: IO ()
main = do
putStrLn "Welcome to FP Haskell Center!"
putStrLn "Have a good day!"
putStrLn $ show $ middle [1]
putStrLn $ show $ middle [1,2]
@gclaramunt
gclaramunt / unboxed.hs
Created July 11, 2014 16:38
Dangeours haskell
{-# LANGUAGE MagicHash #-}
-- | Main entry point to the application.
module Main where
import GHC.Exts
-- | The main entry point.
main :: IO ()
main = do
putStrLn $ showUnboxedInt 1#
@gclaramunt
gclaramunt / Factory.scala
Created June 10, 2014 16:29
Attempt to a typesafe factory patter in scala
/**
* Created by claramun on 6/9/14.
*/
trait A
trait B { val value:String }
trait X1A extends A
trait X1B extends B
@gclaramunt
gclaramunt / all.scm
Created April 22, 2014 01:35
Lot of exercises from "The Little Schemer"
#lang scheme
(define atom? (let ((f1 pair?) (f2 not)) (lambda (x) (f2 (f1 x)))))
(define lat?
(lambda (lat)
(cond
((null? lat) #t)
((atom? (car lat)) (lat? (cdr lat)))
(else #f)
)))
@gclaramunt
gclaramunt / Trick.scala
Last active August 29, 2015 13:56
Evil trick using implicits to customize error messages in a validation
abstract class MyTry[T] {
def get: T
def flatMap[U](f: T => MyTry[U]): MyTry[U]
def map[U](f: T => U): MyTry[U]
def filter(p: T => Boolean)(implicit msg:Msg[T]): MyTry[T]
}
object MyTry {
def apply[T](r: => T): MyTry[T] =
@gclaramunt
gclaramunt / Regular1.scala
Created January 21, 2014 13:44
The code is probably incorrect, but it doesn't report the line where the error happens.
import scala.language.higherKinds
object Regular1 {
trait Bifunctor[F[_, _]] {
def bimap[A, R, B, S](fa: F[A, R], f: A => B, g: R => S): F[B, S]
}
trait Regular2[T[_]]{
def from2[A,PF2[_,_]]:T[A]=>PF2[A,T[A]]
https://github.com/fedesilva/tm2013-hello-play-scala.git
https://github.com/fedesilva/tm2013-hello-akka.git
https://github.com/fedesilva/tm2013-reactive-stocks.git