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
| scala> import scalaz._ | |
| import scalaz._ | |
| scala> case class Person(name: String, age: Int) | |
| defined class Person | |
| scala> val nameLens: Lens[Person, String] = | |
| | Lens((p: Person) => p.name, | |
| | (p: Person, changed: String) => p.copy(name = changed)) | |
| nameLens: scalaz.Lens[Person,String] = Lens(<function1>,<function2>) |
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
| (require 'generic-x) | |
| (defvar roy-keywords | |
| '("with" "macro" "return" "bind" "do" "case" "match" | |
| "type" "data" "else" "then" "if" "fn" "let" "true" "false") | |
| "Roy keywords.") | |
| ;; | |
| ;; Syntax highligh | |
| ;; |
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
| -- courtesy of hpc on #haskell | |
| import Unsafe.Coerce | |
| import Control.Monad.ST | |
| toInteger :: Int -> Integer | |
| isJust :: Maybe a -> Bool | |
| null :: [a] -> Bool | |
| id :: a -> a | |
| toInteger = unsafeCoerce |
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 Control.Applicative | |
| main = print $ answer succ 0 where | |
| one = pure <*> (pure :: a -> b -> a) | |
| inc = (<*>) ((<*>) <$> pure) | |
| mul = (<*>) <$> pure | |
| h = mul <*> inc | |
| answer = h . h . h $ one |
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
| > console | |
| [info] Starting scala interpreter... | |
| [info] | |
| Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_24). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> import scala.xml._ | |
| import scala.xml._ |
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
| $ ghci | |
| GHCi, version 7.4.2: 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> :l hello-ski.hs | |
| [1 of 1] Compiling Main ( hello-ski.hs, interpreted ) | |
| Ok, modules loaded: Main. | |
| *Main> main | |
| Hello world! |
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
| \documentclass{tufte-handout} | |
| %\geometry{showframe}% for debugging purposes -- displays the margins | |
| \usepackage{amsmath} | |
| % Set up the images/graphics package | |
| \usepackage{graphicx} | |
| \setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio} | |
| \graphicspath{{graphics/}} |
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
| class Monad m => Ref r m where | |
| ref :: a -> m (r a) | |
| (*) :: r a -> m a | |
| (*=) :: r a -> a -> m () | |
| (*$) :: r a -> (a -> a) -> m () | |
| r *$ f = (r *) >>= (*=) r . f | |
| instance Ref IORef IO where | |
| ref = newIORef | |
| (*) = readIORef |
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
| case class T() // your data type that you want to "implicitly" thread through | |
| case class TReader[+A](run: T ⇒ A) { | |
| def map[B](f: A ⇒ B): TReader[B] = | |
| TReader((r: T) ⇒ f(run(r))) | |
| def flatMap[B](f: A ⇒ TReader[B]): TReader[B] = | |
| TReader((r: T) ⇒ f(run(r)).run(r)) | |
| def &&&[B](x: TReader[B]): TReader[(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
| case class State[S, +A](run: S ⇒ (A, S)) { | |
| def map[B](f: A => B): State[S, B] = | |
| State(s ⇒ { | |
| val (a, t) = run(s) | |
| (f(a), t) | |
| }) | |
| def flatMap[B](f: A ⇒ State[S, B]): State[S, B] = | |
| State(s ⇒ { | |
| val (a, t) = run(s) |