Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / concurrent_port_scanner.hs
Created October 26, 2016 19:12 — forked from xandkar/concurrent_port_scanner.hs
Concurrent port scanner in Haskell
-- http://blog.moertel.com/articles/2004/03/13/concurrent-port-scanner-in-haskell
module Main (main) where
import Control.Concurrent
import Control.Exception
import Data.Maybe
import Network
import Network.BSD
import System.Environment
@caiorss
caiorss / ghci-conf-test.hs
Last active October 26, 2016 16:35
Haskell configuration file ~/.ghc/ghic.conf for Haskell 8.0.1
-- Test of ghci.conf
--
> :{
- add :: Int -> Int -> Int
- add x y = x * y
- :}
add :: Int -> Int -> Int
> add 10 20
200
@caiorss
caiorss / EceptT_Haskell.hs
Last active October 27, 2016 04:23
Haskell monad transformer
{- ExceptT Monad transformer:
-}
import Control.Monad.Trans
import Control.Monad.Identity
import Text.Read (readMaybe)
import Control.Monad.Trans.Except
-- Turns a maybe value into a Either value

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@caiorss
caiorss / README.md
Created October 25, 2016 03:58 — forked from Y4suyuki/README.md
Monad

Monad

What is Monad?

A monad M is a parametric type M[T] with two operations flatMap and unit that have to satisfy some laws.

trait M[T] {
  def flatMap[U](f: T => M[U]): M[U]
}

def unit[T](x: T): M[T]
@caiorss
caiorss / abstracting-over-monads.md
Created October 25, 2016 03:38 — forked from aryairani/abstracting-over-monads.md
Abstracting over Monads

Abstracting over Monads

We're going to do some computation.

def compute(x: Int, y: Int): Int = x + y

But we want to compute over Option:

@caiorss
caiorss / ReaderMonad.scala
Created October 25, 2016 03:34 — forked from shinnya/ReaderMonad.scala
Reader Monad
object ReaderMonad {
class Reader[-E, +R] private (g: E => R) {
def apply(env: E): R = g(env)
def map[A](f: R => A): Reader[E, A] = new Reader[E, A](env => f(g(env)))
def flatMap[A, B <: E](f: R => Reader[B, A]): Reader[B, A] = new Reader[B, A](env => f(g(env))(env))
}
def pure[E, R](v: R): Reader[E, R] = Reader.pure(v)
def ask[E]: Reader[E, E] = Reader.ask
case class Reader[C, A](g: C => A) {
def apply(c: C) = g(c)
def map[B](f: A => B): Reader[C, B] =
(c:C) => f(g(c))
def flatMap[B](f: A => Reader[C, B]): Reader[C, B] =
(c:C) => f(g(c))(c)
}
object Reader {
implicit def Reader[A,B](f: A => B): Reader[A,B] = Reader(f)

These are some questions to give a sense of what you know about FP. This is more of a gauge of what you know, it's not necessarily expected that a single person will breeze through all questions. For each question, give your answer if you know it, say how long it took you, and say whether it was 'trivial', 'easy', 'medium', 'hard', or 'I don't know'. Give your answers in Haskell for the questions that involve code.

Please be honest, as the interviewer may do some spot checking with similar questions. It's not going to look good if you report a question as being 'trivial' but a similar question completely stumps you.

Here's a bit more guidance on how to use these labels:

  • 'trivial': need at most 15 seconds or so of thinking for each part of your answer you actually write down, and your answer is immediately correct (example - the answer is one line of Haskell, and you immediately can write it out without having to think much)
  • 'easy': need a minute or two of thinking for each part of your answer you actua
@caiorss
caiorss / Scala.For.The.Impatient.md
Created October 25, 2016 02:03 — forked from hhimanshu/ Scala.For.The.Impatient.md
Scala for the Impatient Exercises

This gist will contain all the exercises from the book