Skip to content

Instantly share code, notes, and snippets.

View Philonous's full-sized avatar

Philipp Balzarek Philonous

View GitHub Profile
@Philonous
Philonous / newToARecFast.dump-simpl
Created May 14, 2021 18:42
SmallArray#-based toArecFast
-- RHS size: {terms: 166, types: 1,141, coercions: 387, joins: 0/1}
$wmkToARecFast
:: Int#
-> ARec
ElField
'[ '("a0", Int), '("a1", Int), '("a2", Int), '("a3", Int),
'("a4", Int), '("a5", Int), '("a6", Int), '("a7", Int),
'("a8", Int), '("a9", Int), '("a10", Int), '("a11", Int),
'("a12", Int), '("a13", Int), '("a14", Int), '("a15", Int)]
$wmkToARecFast
-- RHS size: {terms: 73, types: 246, coercions: 177, joins: 2/2}
go
:: forall (ts' :: [(Symbol, *)]).
([Any] -> [Any])
-> Rec ElField ts'
-> ARec
ElField
'[ '("a0", Int), '("a1", Int), '("a2", Int), '("a3", Int),
'("a4", Int), '("a5", Int), '("a6", Int), '("a7", Int),
'("a8", Int), '("a9", Int), '("a10", Int), '("a11", Int),
-- RHS size: {terms: 176, types: 4,182, coercions: 248, joins: 0/0}
$wsumRec :: Rec ElField Fields -> Int#
$wsumRec
= \ (w :: Rec ElField Fields) ->
case w of { :& @ r1 @ rs1 co1 x1 xs ->
case x1 `cast` <Co:4> of { Field @ s @ t co $dKnownSymbol ds ->
case ds `cast` <Co:4> of { I# x ->
case xs `cast` <Co:8> of { :& @ r2 @ rs2 co2 x2 xs1 ->
case x2 `cast` <Co:4> of
{ Field @ s1 @ t1 co3 $dKnownSymbol1 ds1 ->
@Philonous
Philonous / AccessorsBench.hs
Created May 9, 2021 14:26
Vinyl Accessor benchmark
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs #-}
import Control.Monad (unless)
import Criterion.Main
import Data.Monoid (Endo(..))
Import Module As #Packages #Packages Total Percentage
Data.Text T 2471 3293 75.0%
Data.Text Text 606 3293 18.4%
Data.Text TS 50 3293 1.5%
Data.Text ST 35 3293 1.1%
Data.ByteString BS 1172 2907 40.3%
Data.ByteString B 1112 2907 38.3%
Data.ByteString S 267 2907 9.2%
Data.ByteString ByteString 110 2907 3.8%
Data.ByteString SB 55 2907 1.9%
Module Short Name #Packages
Data.Text T 2471
Data.Map Map 1424
Data.Map M 1392
Data.ByteString BS 1172
Data.ByteString B 1112
Data.Set Set 1054
Data.Vector V 912
Data.Set S 670
Data.Text Text 606
Module Short name Instances
Data.Text T 8233
Data.Map Map 4679
Data.Map M 4307
Data.Set Set 3286
Data.ByteString B 2867
Data.ByteString BS 2664
Data.Vector V 2156
Data.Set S 1879
Data.Text Text 1830
Prelude> :set -fbreak-on-exception
Prelude> error "abc"
Stopped in <exception thrown>, <unknown>
_exception :: e = _
[<unknown>] [<unknown>] Prelude> :steplocal
*** Exception: Pattern match failure in do expression at ghc/GHCi/UI.hs:3149:12-18
@Philonous
Philonous / Goto.hs
Created August 23, 2017 12:30
GOTO (kind of) in Haskell
module Goto where
import Control.Monad.Cont
import Data.IORef
evalContT :: Monad m => ContT r m r -> m r
evalContT = flip runContT return
reset :: (Monad m) => ContT a m a -> ContT a m a
reset = lift . evalContT
-- | Unsorted Records based on HashMaps
--
-- Instead of ensuring type safety by construction we create a coincidence
-- between value and type level. This is less save but allows us to work with
-- HashMaps instead of linked lists
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}