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
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 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 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 |
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
-- Trick for expressing contexts like (∀ a. Binary a => Binary (f a)) | |
-- | |
-- This type class says that if we have dictionary for data type `a' we can | |
-- construct dictionary for `f a' or equivalently that if `a' is instance of | |
-- Binary `f a' is instance too. | |
class Binary2 f where | |
binaryDict :: BinaryDict a -> BinaryDict (f a) | |
data BinaryDict a where | |
BinaryDict :: Binary a => BinaryDict 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
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Sum where | |
import Data.Vector.Fixed (S,Z,Fun(..)) | |
import Data.Vector.Fixed.Cont (Fn,Arity(..)) |
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
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE KindSignatures #-} | |
module TySet where | |
type InsertRes x set = If (Member x set) set (x ': set) |
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
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE KindSignatures #-} |
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
import Criterion.Main | |
---------------------------------------------------------------- | |
-- Unit types | |
data U10 = | |
U10_01 | |
| U10_02 | |
| U10_03 | |
| U10_04 |
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
{-# 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 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) |
OlderNewer