Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

-- This code will run into an infinite loop when the strict state
-- monad is used while it terminates just fine for the lazy state
-- monad. In particular monadic binds in the strict state monad cannot
-- depend on values defined later while this is possible in the lazy
-- state monad.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.Monad.Fix
@cocreature
cocreature / Derangement.hs
Created January 10, 2018 18:32
An explanation for the benchmark results in https://github.com/vmchale/ats-benchmarks
-- This gist provides an explanation for why Haskell is significantly
-- faster than ATS and Rust in [vmchale’s great
-- benchmarks](https://github.com/vmchale/ats-benchmarks). What’s
-- happening is that the `derangements` list gets memoized so the
-- benchmark only checks the performance of (!!). `derangements'`
-- prevents GHC from memoizing the list and results in a significant
-- loss of performance. Criterion does try to prevent memoization but
-- it only prevents memoization of the function application (that’s
-- why the function and the argument need to be passed separately to
-- `nf`). It cannot prevent the memoization of the `derangements`
Inductive ev_dumb : nat -> Prop :=
| EvDBase : ev_dumb 0
| EvDRec : forall n, ev_dumb n /\ n <> 1 -> ev_dumb (S (S n)).
Lemma ev_dumb_ind' :
forall P : nat -> Prop,
P 0 ->
(forall n : nat, P n -> ev_dumb n /\ n <> 1 -> P (S (S n))) ->
forall n : nat, ev_dumb n -> P n.
Proof.
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
import Protolude hiding (for)
import GHC.Base (String)
import Pipes
import qualified Pipes.Prelude as P
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, TupleSections #-}
import Data.Typeable
import Data.Aeson as Aeson
import Data.Text (Text)
import GHC.Generics
import qualified Data.HashMap.Lazy as LHM
newtype HStoreList = HStoreList {fromHStoreList :: [(Text,Text)]} deriving (Typeable, Eq, Show, Generic)
instance FromJSON HStoreList where
{-# LANGUAGE BangPatterns, DataKinds, DeriveGeneric, FlexibleContexts, GADTs, OverloadedStrings, RecordWildCards, ScopedTypeVariables, TypeOperators #-}
module Lib
( fieldByName
, deserialize
) where
import Control.Monad.Extra
import Control.Monad.Reader
import Control.Monad.State
import Data.ByteString (ByteString)
module Main where
import LLVM.AST
import qualified LLVM.AST as AST
import LLVM.AST.AddrSpace
import qualified LLVM.AST.CallingConvention as CC
import qualified LLVM.AST.Constant as C
import LLVM.AST.Global
import LLVM.AST.Linkage
import LLVM.Context
;;; core-modeline.el
;; This file tries to be an almost self-contained configuration of my mode-line.
;;
;; It depends on the following external packages:
;; + REQUIRED
;; + powerline
;; + evil-mode
;; + projectile
;; + DejaVu Mono for Powerline font <https://github.com/powerline/fonts>
//===-- examples/clang-interpreter/main.cpp - Clang C Interpreter Example -===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang/CodeGen/CodeGenAction.h"
import Test.Hspec
import Control.Exception
import Control.Concurrent
main :: IO ()
main =
hspec $
describe "it" $
do it "should run" $