Skip to content

Instantly share code, notes, and snippets.

GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> data Foo = Foo Int deriving Show
Prelude> Foo 3
Foo 3
Prelude> instance Eq Foo
Prelude> Foo 3 == Foo 3
*** Exception: stack overflow
scala> case class Matcher[A](f: A => Boolean) {
| def unapply(a: A) = f(a)
| }
defined class Matcher
scala> case class Extractor[A, B](f: A => Option[B]) {
| def unapply(a: A) = f(a)
| }
defined class Extractor
sealed trait Iteration[+R] {
def foreach(f: R => Unit): Unit = this match {
case Yield(r, next) => f(r); next().foreach(f)
case Done => ()
}
def map[S](f: R => S): Iteration[S] = this match {
case Yield(r, next) => Yield(f(r), () => next().map(f))
case Done => Done
}
Option[A]#flatMap[B](f: A => Option[B]): Option[B]
Seq[A]#flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Seq[A], B, That]): That
Future[A]#flatMap[B](f: A => Future[B])(implicit ec: ExecutionContext): Future[B]
scala> def foo[A <: AnyRef](xs: List[A]) = xs.map { case (x: Int) => x }
<console>:7: error: pattern type is incompatible with expected type;
found : Int
required: Object
def foo[A <: AnyRef](xs: List[A]) = xs.map { case (x: Int) => x }
^
scala> def foo[A <: AnyRef](xs: List[A]) = xs.map { case (x: String) => x }
foo: [A <: AnyRef](xs: List[A])List[String]
1.9.3-p374 :020 > def foo; yield; end
=> nil
1.9.3-p374 :021 > method(:foo).arity
=> 0
1.9.3-p374 :022 > foo
LocalJumpError: no block given (yield)
from (irb):20:in `foo'
from (irb):22
from /Users/rahulphulore/.rvm/rubies/ruby-1.9.3-p374/bin/irb:16:in `<main>'
1.9.3-p374 :023 > foo { puts "hello" }
scala> new org.specs2.mutable.Specification {}
res2: org.specs2.mutable.Specification = $anon$1@36e16c4b
scala> import res2._
import res2._
scala> 4 mustEqual 4
res3: org.specs2.matcher.MatchResult[Any] = MatchSuccess(<function0>,<function0>,org.specs2.matcher.MustThrownExpectations$$anon$4@67c522b7)
scala> 4 must beEqualTo(4)
Prelude Control.Applicative> getZipList $ (\n s -> show n ++ show s) <$> ZipList [3, 4] <*> ZipList ['x', 'y']
["3'x'","4'y'"]
# seen through types
https://twitter.com/puffnfresh/status/497379168221270017
http://www.reddit.com/r/haskell/comments/2cv6l4/clojures_transducers_are_perverse_lenses/
http://conscientiousprogrammer.com/blog/2014/08/07/understanding-cloure-transducers-through-types/?utm_content=buffer8516d&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer
# more remarks
https://twitter.com/shajra/status/497367827138215936
https://twitter.com/aloiscochard/status/497311710609670144
https://twitter.com/puffnfresh/status/497360485285912576
https://twitter.com/nbspnbsp/status/497482412947828736
@missingfaktor
missingfaktor / gist:3491fdaaaa012065ea76
Last active August 29, 2015 14:05
Which "functional language" to learn?

(Written in response to this tweet.)

Has .NET been your primary development platform and are you intimately familiar with it? If yes, go for F#.

If you want to be employable soon for this new skill you are learning, or if you want to at least be able to use it in real world easily, you should choose between Scala and Clojure. Both run on JVM, work well with the JVM ecosystem, and have seen a significant adoption over past few years.

Although Scala and Clojure are both categorized as "functional languages", the way of thinking in the two is significantly different.

Scala will introduce you to thinking in types, ADTs, and in computational abstractions such as Applicative Functors and Monads. While doing so, it does not eschew OOP, but in fact, improves on it significantly, and in a principled manner. Though to develop appreciation for that bit takes much practice and meditation. It can also be a gateway drug to the world of advaced typed FP, de