Skip to content

Instantly share code, notes, and snippets.

@wrwills
wrwills / tictactoe
Created October 2, 2018 14:48
tictactoe
sealed trait TicTacToePlayer
case object X extends TicTacToePlayer
case object Y extends TicTacToePlayer
case class TicTacToeBoard(moves: List[(Int,TicTacToePlayer)]) {
val boardRange = 0 to 8
val players = List(X,Y)
lazy val movesMap = moves.toMap
@wrwills
wrwills / LensTest.scala
Created November 30, 2010 13:47
playing with some of the ideas from the Haskell fclabels library using the new Lens functionality in scalaz
import scalaz._
/**
* playing with some of the ideas from the Haskell fclabels library
* using the new Lens functionality in scalaz
*
* http://hackage.haskell.org/package/fclabels
*/
object LensTest {
@wrwills
wrwills / abbrevs.el
Created December 21, 2010 15:55
abbrevs for working with scalaz unicode in emacs; put in .emacs or M-x eval-region in scratch; and then allow to be saved on exit; activate with M-x abbrev-mode
(define-abbrev-table 'global-abbrev-table '(
("alpha" "α" nil 0)
("beta" "β" nil 0)
("gamma" "γ" nil 0)
("theta" "θ" nil 0)
("inf" "∞" nil 0)
("|@|" " ⊛" nil 0)
("forever" "∞" nil 0)
("jjoin" "μ" nil 0)
("cojoin" "υ" nil 0)
/*
* Counterparty A receives: 1.43% absolute on amortising notional (decreasing periodically from an initial notional of £200m).
Counterparty B receives: Previous coupon + 5 x [Max(Ref Index – 6.65%, 0.00%) + Max(2% - Ref Index, 0.00%)] on fixed notional of £200m.
The reference index is CMS EUR 10y set in arrears, available on Reuters website at ISDAFIX2
A Bermudan call option is conferred on Counterparty B who may terminate for 0 payment within a 10 day band every quarter.
Payment dates are quarterly, reset dates and accrual periods are also defined.
@wrwills
wrwills / smtp.hs
Created October 18, 2010 13:31
mime-mail + HaskellNet
import Network.Mail.Mime
import qualified Data.ByteString.Lazy.UTF8 as LU
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString as S
import Control.Monad
import qualified HaskellNet.SMTP as HN
import Text.Pandoc
import Text.Hamlet
import Text.XHtml.Transitional hiding ( renderHtml )
@wrwills
wrwills / OptionGolf.scala
Created October 8, 2010 14:19
applicative_example
import scalaz._
/**
* A simple example of how applicative functors can shorten code
* adapted from chapter 8? of Real World Haskell
*/
object OptionGolf {