Skip to content

Instantly share code, notes, and snippets.

View viercc's full-sized avatar

Koji Miyazato viercc

View GitHub Profile
{-
https://www.reddit.com/r/haskell/comments/g6kc33/intersection_of_infinite_lists/
-}
import qualified Data.Set as Set
-------- Original and Step 1 --------
intersection :: (Eq a) => [[a]] -> [[a]] -> Int -> [([a], [a])]
intersection l1 l2 i =
[(x, y) | x <- (take i l1), y <- (take i l2), not (common x y == [])]
@viercc
viercc / hashtable.hs
Last active March 30, 2020 08:41
On hashtables with "undo-able" insert
-- Just wrote down in the web editor.
-- Not tested at all but I hope you get the idea
import qualified Data.HashTable.ST.Basic as HT
import Data.List.NonEmpty(NonEmpty(..))
import qualified Data.List.NonEmpty as NE
type MyHashTable s k v = HT.HashTable s k (NonEmpty v)
insert :: MyHashTable s k v -> k -> v -> ST s ()
@viercc
viercc / eval_by_hkd.hs
Created March 22, 2020 07:55
Overkilling again: "Monthly Hask Anything" question Mar 2020
-- https://www.reddit.com/r/haskell/comments/fbfhum/monthly_hask_anything_march_2020/fl4fgek/
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
import Data.Word
import Data.Functor.Identity
-- Breaking first-class-instances
{-#
LANGUAGE
TemplateHaskell,
RankNTypes,
TypeFamilies,
KindSignatures,
FlexibleInstances,
ConstraintKinds
#-}
@viercc
viercc / Output
Created November 23, 2019 02:45
Trying GHCJS
$ ghcjs -O2 test.hs
[1 of 1] Compiling Main ( test.hs, test.js_o )
Linking test.jsexe (Main)
$ (cd test.jsexe/ && node all.js)
(0,1)
(1,2)
(2,4)
(3,8)
(4,16)
(5,32)
@viercc
viercc / q.cpp
Last active November 11, 2019 13:36
tmp
[In Haskell]
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr = ......
(example)
foldr (+) 0 [a,b,c] = a + (b + (c + 0))
[In C++]
@viercc
viercc / w.hs
Created November 9, 2019 11:56
That's not ~~intuitive~~ intuitionistic
{-
@lexi_lambda (at twitter)
https://mobile.twitter.com/lexi_lambda/status/1192930938537332736?s=19
-}
{-# LANGUAGE RankNTypes #-}
class Foo()
// フィールドが一つもないクラスを定義し、そのクラスのオブジェクトを作ると
// コンパイラ自体がSegmentation Faultを起こす
//@one_field = 0
@function g()
ans = "0"
return ans
x = Foo()
@viercc
viercc / flexible-instances-in-wild.md
Last active October 5, 2019 01:03
Flexible Instances I have found in wild
@viercc
viercc / ProofOfContEq.md
Last active January 23, 2019 03:25
On How to define Eq on Cont r a

Let's define a type class Searchable.

class Searchable a where
    epsilon :: (a -> Bool) -> a

    -- [Law]
    --  (∃x :: a. p a == True) => p (epsilon p) = True

We want to show that the following instance is valid.