Skip to content

Instantly share code, notes, and snippets.

View akhileshs's full-sized avatar

Akhilesh Srikanth akhileshs

  • San Francisco, CA
View GitHub Profile
class CanQuack a where
quack :: a -> IO ()
class HasFeathers a where
feathers :: a -> IO ()
data Duck = Duck
data Person = Person
instance CanQuack Duck where
{-# 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)
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
data PrimExpr =
BinExpr BinOp PrimExpr PrimExpr
| UnExpr UnOp PrimExpr
| ConstExpr String
| IntExpr Int
| BoolExpr Bool
data BinOp =
OpEq
| OpAnd
{- ----------------------------------------------------------------------
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).
sequence :: Monad m => [m a] -> m [a]
sequence = foldr mcons (return [])
where mcons p q = p >>= \x -> q >>= \y -> return (x : y)
trait Vect[Size, A]
def ++[n, m, a](v1: Vect[n, a], v2: Vect[m, a]): Vect[(n + m), a]
data Toy b next =
Output b next
| Bell next
| Done
deriving (Show)
data FixE f e = Fix (f (FixE f e)) | Throw e
catch :: (Functor f) => FixE f e1 -> (e1 -> FixE f e2) -> FixE f e2
catch (Fix x) f = Fix (fmap (flip catch f) x)
{-# LANGUAGE RankNTypes #-}
module F where
data User = User { name :: String, age :: Int } deriving Show
data Project = Project { owner :: User } deriving Show
type Lens s a = Functor f => (a -> f a) -> s -> f s
newtype Identity a = Identity { runIdentity :: a }
scala> type Foo[A, B] = Map[A, B]
defined type alias Foo
scala> type World[M[_]] = M[Int]
warning: there was one feature warning; re-run with -feature for details
defined type alias World
scala> type X[A] = World[({ type M[A] = Foo[String, A] })#M]
defined type alias X