Skip to content

Instantly share code, notes, and snippets.

View akhileshs's full-sized avatar

Akhilesh Srikanth akhileshs

  • San Francisco, CA
View GitHub Profile
{- ----------------------------------------------------------------------
Raw code file for "Evolution of a Haskell Programmer"
Fritz Ruehr, Willamette University
See <http://www.willamette.edu/~fruehr/haskell/evolution.html>
Any given variation section (seperated by horizontal rules) can be enabled
by setting off its delimiting nested comments with EOL comments
(in which case the previously enabled section should be disabled).
data PrimExpr =
BinExpr BinOp PrimExpr PrimExpr
| UnExpr UnOp PrimExpr
| ConstExpr String
| IntExpr Int
| BoolExpr Bool
data BinOp =
OpEq
| OpAnd
data Message = PlainText String | Encrypted String
send :: Message -> Recipient -> IO ()
send (Encrypted m) recipient = some magic with m
send (PlainText _) _ = undefined
data Maybe a = Just a | Nothing
-- movin' to phantom types
data Message a = Message String
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid
import Typed.Spreadsheet
celsius = spinButton "Celsius" 0.1
convert c = "Fahrenheit: " <> display (c * 9 / 5 + 32)
main = textUI "Celsius to Fahrenheit converter" (fmap convert celsius)
class CanQuack a where
quack :: a -> IO ()
class HasFeathers a where
feathers :: a -> IO ()
data Duck = Duck
data Person = Person
instance CanQuack Duck where
@akhileshs
akhileshs / springer-free-maths-books.md
Created December 28, 2015 13:08 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links
scala> case class B[F, T](c: B[F, T] => (F => T)) extends (B[F, T] => (F => T)) {
| def apply(b: B[F, T]) = c(b);
| }
defined class B
scala> def Y[F, T] = (f: (F => T) => F => T) =>
| B[F, T](x => f(x(x)(_)))(B(x => f(x(x)(_))))
Y: [F, T]=> ((F => T) => (F => T)) => (F => T)
scala> trait Exp { def eval() : Int }
defined trait Exp
scala> trait Lit extends Exp {
| val x : Int
| def eval() = x
| }
defined trait Lit
scala> trait Add extends Exp {
scala> trait T[+A] {
| def flatMap[B](f: A => T[B]): T[B] // bind operation
| def map[B](f: A => B): T[B]
| }
defined trait T
(ns fluokitty.core
(:use [uncomplicate.fluokitten core jvm]))
(map inc [1 2 3])
(fmap inc [1 2 3])
(fmap + [1 2 3] [1 2 3 4])
(fmap + [1 2 3] (list 1 2 3))