This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait HTree | |
case class HTNode[T, LT <: HTree,RT <: HTree](node:T, lt:LT, rt:RT ) extends HTree | |
case class HTNil() extends HTree | |
/* | |
exmaple: | |
scala> HTNode ( 1, HTNode("a",HTNode(1.0,HTNil(),HTNil()), HTNode('z',HTNil(),HTNil())), HTNode(List(1,2,3),HTNil(),HTNil())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Entity | |
trait User extends Entity | |
trait Product extends Entity | |
case class Id[T<:Entity](id:String) | |
def buy(pId:Id[Product],uId:Id[User])="Bought product %s for user %s".format(pId.id,uId.id) | |
val pId=new Id[Product]("1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p ~/.vim/{ftdetect,indent,syntax} && for d in ftdetect indent syntax ; do wget -O ~/.vim/$d/scala.vim https://raw.github.com/scala/scala-dist/master/tool-support/src/vim/$d/scala.vim ; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, Rank2Types, TypeOperators #-} | |
newtype Id a = | |
Id a | |
data a :\/ b = | |
Left a | |
| Right b | |
data a :/\ b = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection | |
trait Closeable[T]{ | |
def close(t:T) | |
} | |
object Closeable{ | |
implicit val connectionCloseable= new Closeable[Connection]{ | |
override def close(c:Connection){ c.close() } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._, Nat._ | |
trait FizzBuzz[N <: Nat] { | |
type R3 <: Nat | |
type R5 <: Nat | |
def ti: ToInt[N] | |
def prev: List[String] | |
def d3: R3 =:= _0 | |
def d5: R5 =:= _0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've been pondering this myself the last few days, and I'd like to go ahead and amplify this. Don't worry about leaping to the "Haskelly" solution at first. Start by just bashing something out that essentially works. Go nuts. Do it all in IO. Write partial functions. Copy and paste without fear. Use undefined to fill in gaps in the functions. Realize halfway through you're sort of doing it wrong, but don't stop to correct it, just keep going straight for something that works for some task. Not even the whole task, just something. | |
(Do avoid mutation, though, that will wreck up the rest of this process. Stay out of IORef, and for the moment I'd even suggest avoiding Control.Monad.State, although that's much less bad.) | |
You will quite likely look at the resulting code, and wonder why you bothered doing it in Haskell. It looks like crap, was harder to write than whatever language you are comfortable in (for the compiler was probably still pretty cranky at you even so), and looks nothing like the beautiful code you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CALL=${1:-"cabal build"} | |
$CALL | |
while inotifywait -qq -r -e modify .; do | |
echo '<><><><> Starting build <><><><>'; | |
echo `date`; | |
$CALL; | |
echo '<><><><> Done <><><><>'; | |
sleep 1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def avg(xs:List[Int]):Float={ | |
val (sum,length)=xs.foldLeft((0,0))( { case ((s,l),x)=> (x+s,1+l) }) | |
sum/length | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List("129.95.30.40","5.24.69.2","19.20.203.5","1.2.3.4","19.20.21.22","5.220.100.50"). | |
map(_.split('.').map(_.toInt)). | |
map( { case Array(x1,x2,x3,x4) => (x1,x2,x3,x3) } ).sorted. | |
map { case (x1,x2,x3,x4) => "%s.%s.%s.%s".format(x1,x2,x3,x4)} |