Skip to content

Instantly share code, notes, and snippets.

View viercc's full-sized avatar

Koji Miyazato viercc

View GitHub Profile
@viercc
viercc / gist:37b66810257fce0489c7ffff05fbb873
Last active February 4, 2022 05:01
反対圏でのstrength
@viercc
viercc / angles.hs
Last active December 10, 2021 11:25
プログラム
#!/usr/bin/env cabal
{- cabal:
build-depends: base, vector
-}
module Main where
import Data.Foldable (foldl')
import Control.Monad (guard)
import qualified Data.Vector.Unboxed as V
@viercc
viercc / Logistic.hs
Last active November 20, 2021 16:38
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
module Logistic where
import Data.Kind ( Type )
import Data.Functor.Const
import Data.Functor.Contravariant

Q: Is there an instance Monad ZipList compatible with Applicative ZipList?

A: No.

Proof.

Use these definitions

(<&>) :: Functor f => f a -> (a -> b) -> f b
@viercc
viercc / StrangeFilterable.hs
Created October 6, 2021 01:12
StrangeFilterable.hs
{-# LANGUAGE DeriveTraqversable #-}
import Witherable
newtype T a = MkT [a]
deriving (Show, Eq, Functor, Foldable, Traversable)
instance Filterable T where
-- ひとつでもNothingがあれば空リスト、
-- すべてJustならJustを除いた元のリスト
catMaybes tpa = case sequenceA tpa of
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE GADTs #-}
module CoerceUnder where
@viercc
viercc / sum-mapm.hs
Created July 13, 2021 04:41
summaion by mapM on State vs. by foldl
sum''''' :: Num a => [a] -> a
sum''''' xs = snd $ foldr h (\s -> ((), s)) xs 0
where
h :: Num a => a -> (a -> b) -> a -> b
h x k = \s -> k (s + x)
{-
snd $ foldr h (\s -> ((), s)) xs 0
$ ghc-9.0.1 -fno-code -ddump-to-file -dsuppress-module-prefixes -dsuppress-type-applications -ddump-ds -ddump-splices Main.hs
[1 of 2] Compiling THPatTest ( THPatTest.hs, /tmp/ghc31722_0/ghc_4.o, /tmp/ghc31722_0/ghc_4.dyn_o )
[2 of 2] Compiling Main ( Main.hs, /tmp/ghc31722_0/ghc_2.o, /tmp/ghc31722_0/ghc_2.dyn_o )
$ runghc Main.hs
(2,2,2)
(1,2,1)
@viercc
viercc / Lib.hs
Created March 9, 2021 09:09
Answering effectfully<HYPHEN>ou/haskell<HYPHEN>challenges<SLASH>h4-largest-powers
module Lib
( largestPowersInt ) where
class Eq a => Iterable a where
zer :: a
inc :: a -> a
dec :: a -> a
instance Iterable Int where
zer = 0
@viercc
viercc / Summation.hs
Created May 26, 2020 12:59
For discussion about algorithms to solve a hackerrank excercise
module Summation where
import Data.List (sortBy)
import Data.Ord (comparing)
import qualified Data.Vector.Unboxed as V
type Query = (Int, Int, Int)
test1 :: [Query]
test1 =