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 Criterion.Main | |
---------------------------------------------------------------- | |
-- Unit types | |
data U10 = | |
U10_01 | |
| U10_02 | |
| U10_03 | |
| U10_04 |
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 MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE TypeOperators #-} | |
-- Type constructor for list of types which is used in tests for | |
-- memberhip | |
data 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
$ ghc --make foo | |
[1 of 1] Compiling Main ( foo.hs, foo.o ) | |
Linking foo ... | |
$ ./foo | |
"Starting IO" | |
Warning: Couldn't open "/dev/urandom" | |
Warning: using system clock for seed instead (quality will be lower) | |
"Starting IO" | |
foo: nonexitant: openFile: does not exist (No such file or directory) |
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 MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE DeriveDataTypeable #-} | |
{-# LANGUAGE EmptyDataDecls #-} | |
{-# LANGUAGE Rank2Types #-} |
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 NoMonomorphismRestriction, BangPatterns #-} | |
module Main where | |
-- compile: ghc --make -main-is Prime.main Prime.hs -O2 | |
-- $time ./Prime i 500000 | |
-- ./Prime i 500000 4.35s user 0.00s system 99% cpu 4.453 total | |
-- ./Prime s 500000 7.69s user 0.03s system 99% cpu 7.726 total (!!!) | |
-- lookup OPT in comments about various optimization points | |
import System.Environment(getArgs) |
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 Magic a where | |
conjure :: String -> [a] | |
magikStorage :: [a] -> String | |
-- Use return type | |
doMagik :: Magic a => Int -> [a] | |
doMagik n = concat $ replicate n res | |
where | |
res = conjure $ magikStorage res -- Must be lazy in res !!!! |
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.Default | |
import Debug.Trace | |
data Proxy a = Proxy | |
class Magick a where | |
magickStorage :: Proxy [a] -> String | |
instance Magick Int where | |
magickStorage = const "Int" |
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 Debug.Trace | |
xs1,xs2 :: [Int] | |
xs1 = map (\x -> (trace "2" 2 + trace "3" 3) * x) [0..] | |
xs2 = map (let y = trace "2" 2 + trace "3" 3 in \x -> x*y) [0..] | |
{- | |
*Main> take 4 xs1 | |
[2 | |
3 | |
0,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
import Data.Monoid | |
-- | Type class for monoidal accumulators | |
class Monoid m => Accumulator m a where | |
-- | Convert value to 1-element accumulator | |
unit :: a -> m | |
unit a = cons a mempty | |
-- | Prepend value to accumulator | |
cons :: a -> m -> m | |
cons a m = unit a <> m |
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 ScopedTypeVariables #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module Region76 where |
OlderNewer