Skip to content

Instantly share code, notes, and snippets.

View viercc's full-sized avatar

Koji Miyazato viercc

View GitHub Profile
@viercc
viercc / Check.hs
Last active January 30, 2023 13:37
Note on Distributive laws for semialign package
-- This exists so that I haven't made a silly mistake,
-- like typo or type mismatch of expressions surrounding equal sign.
{-# LANGUAGE TypeOperators #-}
module Check where
import Prelude hiding (zip)
import Data.These
import Data.Zip
import Data.Bifunctor
-- https://www.reddit.com/r/haskell/comments/z9eyu7/monthly_hask_anything_december_2022/izpv48z/
{-# language
DeriveGeneric,
DerivingVia,
StandaloneDeriving,
TypeOperators,
FlexibleInstances,
ScopedTypeVariables,
TypeFamilies,
TypeApplications,
@viercc
viercc / Foldl.hs
Last active November 30, 2022 06:00
Performance of manually implemented foldl' on GHCi
module Foldl(foldl', foldl'Copied, foldl'CopiedMono, foldl'Recursion, foldl'Recursion2) where
import Data.List (foldl')
import GHC.Exts (oneShot)
foldl'Copied :: Foldable t => (b -> a -> b) -> b -> t a -> b
{-# INLINE foldl'Copied #-}
foldl'Copied f z0 = \ xs -> foldr (\ (x::a) (k::b->b) -> oneShot (\ (z::b) -> z `seq` k (f z x))) (id::b->b) xs z0
foldl'CopiedMono :: (b -> a -> b) -> b -> [a] -> b
@viercc
viercc / gadt-filter-with-typeable.hs
Created October 27, 2022 08:08
Generalising / DRYing functions which apply to GADTs
{-# LANGUAGE GADTs, DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Typeable (cast)
import Type.Reflection
@viercc
viercc / CoSemigroup.md
Last active October 16, 2022 09:24
CoSemigroup

Traversableに激似の抽象化たちを整理してみた

tはどんな関手 とる 返す
Traversable t traverse $\mathrm{Hask} \to \mathrm{Hask}$ Star f a b Star f (t a) (t b)
PTraversable t ptraverse $\mathrm{Hask} \to \mathrm{Hask}$ p a b p (t a) (t b)
Bitraversable t bitraverse $\mathrm{Hask}^2 \to \mathrm{Hask}$ Star2 f a₁ a₂ b₁ b₂ Star f (t a₁ a₂) (t b₁ b₂)
Rank2.Traversable t Rank2.traverse $\mathrm{Hask}^k \to \mathrm{Hask}$ IxStar f a b Star f (t a) (t b)
traverseBia $\mathrm
@viercc
viercc / git-status-to-check-nothing-to-commit
Created July 13, 2022 05:01
Using git-status to tell if it's "nothing-to-commit" status
$ ls
foobar.txt hoge.txt piyo.txt
$ git status
ブランチ main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: hoge.txt
追跡されていないファイル:
#!/usr/bin/env cabal
{- cabal:
build-depends: base, vector, process
-}
module Main where
{-
検算
{-# LANGUAGE
GADTs,
RankNTypes,
PolyKinds,
DataKinds,
ScopedTypeVariables,
StandaloneKindSignatures
#-}
module DiscreteCategory where