This file contains 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
> List.map ((+)1) [1..10000000];; | |
Real: 00:00:06.655, CPU: 00:00:07.328, GC gen0: 83, gen1: 64, gen2: 3 | |
val it : int list = | |
[2; 3; 4; 5; 6; 7; 8; ...] | |
> let map_cps f l' = | |
- let rec go l c = | |
- match l with | |
- | [] -> c [] | |
- | (x::xs) -> go xs (fun xs' -> c (f x :: xs')) |
This file contains 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
module Main(main) where | |
foo :: [()] -> () | |
foo x = bar x where | |
bar x = {-# SCC "my" #-} head x | |
main = print $ foo [] | |
{- | |
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: |
This file contains 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
mvmap f v = go $ M.length v where | |
go 0 = return () | |
go (n + 1) = update v n f >> go n |
This file contains 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
{-# OPTIONS_GHC -fstatic-argument-transformation #-} | |
module Main (main) where | |
import Criterion.Main | |
import Control.Monad | |
import Data.List | |
import Data.Functor.Identity | |
foldM' :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a |
This file contains 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
structure S1 = struct | |
fun foo (x:{cells:int list, columns:int, rows:int}) = (#columns x, #rows x, #cells x) | |
end; | |
structure S2 = struct | |
fun foo (x:{cells:int list, columns:int, rows:int}) = (#columns x, #rows x, #cells x) | |
end; | |
S1.foo {columns = 1, rows = 2, cells = [1,2]}; | |
val it = (1,2,[1,2]) : int * int * int list |
This file contains 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
Prelude Control.Monad> :set -XDefaultSignatures | |
Prelude Control.Monad> | |
newtype Box a = Box a deriving Show | |
Prelude Control.Monad> | |
instance Monad Box where | |
return = Box | |
(Box x) >>= f = f x | |
This file contains 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
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> import Control.Exception | |
Prelude Control.Exception> import Data.Typeable | |
Prelude Control.Exception Data.Typeable> | |
newtype Foo = Foo (() -> IO ()) | |
Prelude Control.Exception Data.Typeable> :set -XSafe |
This file contains 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
Prelude> class Pet a where kill :: a -> String | |
Prelude> data Dog = Dog deriving Show | |
Prelude> data Cat = Cat deriving Show | |
Prelude> instance Pet Dog where kill = const "dead" | |
Prelude> instance Pet Cat where kill = const "c_1|dead> + c_2|alive>" | |
Prelude> map kill [Cat, Cat] -- диспетчеризация времени компиляции | |
["c_1|dead> + c_2|alive>","c_1|dead> + c_2|alive>"] | |
Prelude> map kill [Dog, Dog] -- диспетчеризация времени компиляции | |
["dead","dead"] | |
Prelude> data PetBox where Box :: Pet a => a -> PetBox |
This file contains 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
> :{ | |
let merge xs [] = xs | |
merge [] ys = ys | |
merge (x:xs) (y:ys) | x < y = x: merge xs (y:ys) | |
| otherwise = y: merge (x:xs) ys | |
:} | |
> :set -XNoMonomorphismRestriction | |
> let mergeAll = foldr1 merge | |
> take 20 $ mergeAll [[5..],[1..],[3..],[7..],[2..],[1..]] | |
[1,1,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,5,6,6] |
This file contains 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
*Prelude.Type> T::T (Any ((==) 1) '[3,2,1]) | |
True | |
it :: | |
T (Bool -> Constraint) | |
(Any | |
Nat (Nat == 1) ((':) Nat 3 ((':) Nat 2 ((':) Nat 1 ('[] Nat))))) | |
*Prelude.Type> T::T (Any ((==) 1) '[3,2]) | |
False | |
it :: | |
T (Bool -> Constraint) |