Skip to content

Instantly share code, notes, and snippets.

Xia Li-yao Lysxia

Block or report user

Report or block Lysxia

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Lysxia
Lysxia / BinTrees.hs
Last active Oct 23, 2015 — forked from meditans/BinTrees.hs
Enumerating BinTrees by depth
View BinTrees.hs
import qualified Control.Monad.WeightedSearch as W
import Data.List (sortBy)
import Data.Ord (comparing)
import Control.Applicative
data BTree = Leaf | Branch BTree BTree deriving (Show, Eq)
-- I can lazily list all the btrees
btrees :: W.T Integer BTree
btrees = pure Leaf <|> W.weight 1 (Branch <$> btrees <*> btrees)
View BasicBlock.ml
module M = struct
include BasicBlock_types
let f X Y Z = ()
end
View gist:f5e31a527810556c15ae98c688354f8c
forM_ (zip [0, 2..] (makeForm someUser)) $ \(idx, label_name) -> do
createLabel label_name >>= attach idx
Entry.entryNew >>= attach (idx+1)
where
attach idx x = Grid.gridAttach grid x 0 idx 1 1
View Arbitrary.Product.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
module Arbitrary.Product where
import Test.QuickCheck
-- Example
@Lysxia
Lysxia / 708 7.8.4
Last active Mar 20, 2017
aeson benchmarks comparison (pasted together, by GHC version). Left: master. Right: PR #524 (refactor ToJSON/ToEncoding).
View 708 7.8.4
+ date + date
Sun Mar 19 23:30:48 EDT 2017 Mon Mar 20 00:25:05 EDT 2017
+ stack clean + stack clean
+ echo 'Build stack (fast)' + echo 'Build stack (fast)'
Build stack (fast) Build stack (fast)
+ stack build --silent --flag aeson:fast + stack build --silent --flag aeson:fast
real 0m17.276s real 0m16.601s
user 0m16.753s user 0m16.127s
sys 0m0.763s sys 0m0.693s
View 708 7.8.4
time stack build --flag aeson:-fast
real 2m56.368s real 3m7.390s
user 2m55.557s user 2m54.277s
sys 0m1.123s sys 0m1.503s
time stack ghc -- benchmarks/AesonCompareAutoInstances.hs -O0
real 0m7.939s real 0m11.914s
user 0m7.137s user 0m7.927s
View Y.lhs
Applicative style record composition with Vinyl.
> {-# LANGUAGE AllowAmbiguousTypes #-}
> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# LANGUAGE RankNTypes #-}
> {-# LANGUAGE ScopedTypeVariables #-}
> {-# LANGUAGE TypeApplications #-}
> {-# LANGUAGE TypeFamilies #-}
View Tensor.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE UndecidableInstances #-}
View Zip.lhs
> {-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances,
> TypeFamilies, MultiParamTypeClasses, UndecidableInstances,
> RankNTypes, ScopedTypeVariables, FunctionalDependencies, TypeOperators #-}
>
> module Zip where
>
> import Data.Proxy
> import GHC.TypeLits
Let's first assume that the two nested lists have the same depth. E.g., depth 2:
View Knots.hs
module Knots where
import Data.Char (chr, ord)
import Data.Foldable (for_)
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Set as Set
-- See https://en.wikipedia.org/wiki/Combinatorial_map
You can’t perform that action at this time.