Skip to content

Instantly share code, notes, and snippets.

@ssanj
ssanj / Functor.scala
Created February 16, 2011 22:56
Functor definition
List("one", "two", "three") map (_.length)
trait Functor[F[_]] {
def fmap[A,B](f: A => B, fa:F[A]): F[B]
}
class ListFunctor extends Functor[List] {
def fmap[A,B](f: A => B, fa:List[A]): List[B] = fa match {
case Nil => Nil
case x::xs => f(x) :: fmap(f, xs)
case class Person(name:String)
fmap((_:Person).name, Holder(Person("Harry Potter")))
11: error: could not find implicit value for parameter functor: Functor[Holder]
List -> is a type constructor
List[Long] -> is a type
@ssanj
ssanj / Unsafe List
Created March 31, 2011 01:56
Adding any values to a typed List
scala> val ar:List[Int] = Nil
ar: List[Int] = List()
scala> "blah" :: 5 :: 6 :: ar
res21: List[Any] = List(blah, 5, 6)
//how did I add a String to a List[Int]?
//how do you keep the type within the List fixed at Int?
//can I only do that at declaration time as opposed to when I call the :: method?
//This works:
@ssanj
ssanj / gist:905263
Created April 6, 2011 07:14
emacs bindings for scala
;; Load the ensime lisp code...
(add-to-list 'load-path "ENSIME_ROOT/elisp/")
(require 'ensime)
;; This step causes the ensime-mode to be started whenever
;; scala-mode is started for a buffer. You may have to customize this step
;; if you're not using the standard scala mode.
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)
;; MINI HOWTO:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
@ssanj
ssanj / add_iptable_rule.sh
Created November 22, 2011 22:33
iptable_rules
sudo iptables -A CHAIN_NAME
sudo chmod +x /etc/network/if-pre-up.d/iptablesload
@ssanj
ssanj / gist:1623230
Created January 16, 2012 21:54
Cabal install hlint
cabal install hlint
Resolving dependencies...
[1 of 1] Compiling Main ( /var/folders/zn/7pk0j2jd3d5b35n46ybls6s80000gn/T/haskell-src-exts-1.11.15274/haskell-src-exts-1.11.1/Setup.hs, /var/folders/zn/7pk0j2jd3d5b35n46ybls6s80000gn/T/haskell-src-exts-1.11.15274/haskell-src-exts-1.11.1/dist/setup/Main.o )
/var/folders/zn/7pk0j2jd3d5b35n46ybls6s80000gn/T/haskell-src-exts-1.11.15274/haskell-src-exts-1.11.1/Setup.hs:1:0:
Warning: In the use of `runTests'
(imported from Distribution.Simple, but defined in Distribution.Simple.UserHooks):
Deprecated: "Please use the new testing interface instead!"
Linking /var/folders/zn/7pk0j2jd3d5b35n46ybls6s80000gn/T/haskell-src-exts-1.11.15274/haskell-src-exts-1.11.1/dist/setup/setup ...
Configuring haskell-src-exts-1.11.1...
@ssanj
ssanj / gist:1642907
Created January 19, 2012 21:37
uncurry id - Not what I expected
Given: uncurry id
the result is: (b -> c, b) -> c
How does this result come about?
uncurry :: (a-> b -> c) -> (a,b) -> c
id :: a -> a
How can you use id (a -> a) as the first parameter to uncurry, which requires a (a -> b -> c) function?