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 UndecidableInstances #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ExistentialQuantification #-} |
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 MagicHash #-} | |
import Data.Bits | |
import GHC.Prim | |
import GHC.Word | |
import Text.Printf | |
import Data.Char (ord) | |
hasBetween# :: Word# -> Word# -> Word# -> Word# | |
hasBetween# x m 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 -O2 -fforce-recomp -ddump-simpl -dsuppress-all -dsuppress-coercions #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE MultiWayIf #-} | |
import Data.Bits | |
import qualified Data.Vector.Unboxed as UV | |
main :: IO () | |
main = do | |
v <- readLn |
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 BangPatterns #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Data.Bits | |
import Data.Vector (Vector) | |
import qualified Data.Vector.Unboxed as UV | |
import qualified Data.Vector as V | |
import qualified Data.List as L | |
import Test.QuickCheck.All (quickCheckAll) |
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
-- This is a riddle about people's ages that I made up. Below, we solve it | |
-- using the monadic interface to lists. Here it is: | |
-- | |
-- * Jordan is either 13 years old or 16 years old | |
-- * Shen is between 3 and 5 years older than Jordan (inclusive bounds) | |
-- * Claudia is between 6 and 9 years younger than Jordan's age plus Shen's age. | |
-- * I am as old as the three aforementioned people combined. | |
-- | |
-- Given the provided information, I could have many possible ages. The monad | |
-- instance for list models this kind of nondeterminism well. Run the example |
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 ImplicitParams #-} | |
example1 :: (?a :: Int) => [Int] | |
example1 = let ?a = 4 in [foo,bar + bar,(?a + 3) + (?a + 3)] | |
where | |
foo = bar + bar | |
bar = ?a + 3 | |
example2 :: (?a :: Int) => [Int] | |
example2 = let ?a = 4 in [foo,bar + bar,(?a + 3) + (?a + 3)] |
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 BangPatterns #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE UnboxedTuples #-} | |
{-# LANGUAGE RankNTypes #-} | |
-- If you are building with GHC 8.2.1, it is recommonded that | |
-- this module be built with: | |
-- ghc -O2 -fllvm -pgmlo opt-3.9 -pgmlc llc-3.9 prim_bench.hs | |
-- For other GHC versions, choose the appropriate versions of |
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 MagicHash #-} | |
{-# LANGUAGE UnboxedTuples #-} | |
module Example | |
( Stable | |
, stabilize | |
, destabilize | |
) where | |
import GHC.Prim | |
import GHC.ST |
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 BangPatterns #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# OPTIONS_GHC -O2 -Wall -threaded -fforce-recomp #-} | |
import Criterion.Main | |
import Control.Monad (when) | |
import Control.Monad.ST.Unsafe (unsafeDupableInterleaveST,unsafeInterleaveST) | |
import GHC.ST (ST(..)) | |
import GHC.Prim (spark#,seq#) |
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 BangPatterns #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# OPTIONS_GHC -O2 -Wall -threaded -fforce-recomp #-} | |
import Criterion.Main | |
import Control.Monad (when) | |
import Control.Parallel.Strategies (runEval,rpar,rseq) | |
import Control.Concurrent (forkIO) | |
import Control.Concurrent.MVar (newEmptyMVar,takeMVar,putMVar) |