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
<h2>Naive canvas</h2> | |
<canvas id="naive" width="400" height="50"></canvas> | |
<h2>High-def Canvas</h2> | |
<canvas id="hidef" width="800" height="500"></canvas> |
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
{-# Language GADTs #-} | |
data Term a where | |
Lit :: a -> Term a | |
Succ :: Term Int -> Term Int | |
IsZero :: Term Int -> Term Bool | |
If :: Term Bool -> Term a -> Term a -> Term a | |
IsNeg :: Term Int -> Term Bool | |
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 Haste | |
main :: IO () | |
main = do | |
-- Get handle to #msg div | |
msg <- elemById "msg" | |
case msg of | |
Just m -> do | |
-- Handle onClick event |
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
{- For demonstration only; this is deliberately slow recursive code to highlight multicore speedup -} | |
import System.Time | |
import Control.Concurrent | |
import Control.Parallel.Strategies hiding (parMap) | |
import System.Environment | |
fib 0 = 1 | |
fib 1 = 1 | |
fib n = fib (n - 1) + fib (n - 2) |
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
{-# LANGUAGE ExistentialQuantification #-} | |
data Circle = Circle Double deriving (Show) | |
data Square = Square Double deriving (Show) | |
data Rectangle = Rectangle Double Double deriving (Show) | |
-------------------------------------------------------------------------------- | |
-- Each shape implements an area function | |
-------------------------------------------------------------------------------- | |
class Shape s where |
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.Monad.STM | |
import Control.Concurrent | |
import Control.Concurrent.STM.TChan | |
oneSecond = 1000000 -- microseconds | |
-- | This thread writes values to a channel. | |
writerThread :: TChan Int -> IO () | |
writerThread chan = do | |
-- Wait two seconds, then write 1 to channel |
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.Monad | |
import System.Random | |
import Data.List | |
import Data.Ord | |
-- Letters of the alphabet | |
alpha = ['a'..'z'] | |
-- Get a random letter | |
rLetter = randomRIO (0,25) >>= return . (!!) alpha |
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 Data.ByteString.Lazy.Internal | |
import Data.Aeson | |
import Control.Applicative | |
data Person = Person String Int deriving (Show) | |
instance FromJSON Person where | |
parseJSON (Object p) = | |
Person <$> | |
(p .: "name") <*> |
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
-- | Main entry point to the application. | |
module Main where | |
import Control.Monad.Reader | |
import Control.Monad.Writer | |
{- | |
The ReaderT transformer is used to retrieve a read-only value from some environment. | |
The WriterT transformer will log the result of each retrieval. | |
Running the two transformers together yields a log of each step along with the actual results. |
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
-- | Sandbox Haskell package | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
module Main where | |
class Pet animal sound | animal -> sound where | |
speak :: animal -> sound | |
data Sound = Bark | Meow deriving (Show) |
OlderNewer