(I didn't think of kind polymorphism and don't know how that relates to FlexibleInstances)
-- Fixed is owned
| {- | |
| 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 == [])] |
| -- 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 () |
| -- 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 | |
| #-} |
| $ 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) |
| [In Haskell] | |
| foldr :: (a -> b -> b) -> b -> [a] -> b | |
| foldr = ...... | |
| (example) | |
| foldr (+) 0 [a,b,c] = a + (b + (c + 0)) | |
| [In C++] |
| {- | |
| @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() |
(I didn't think of kind polymorphism and don't know how that relates to FlexibleInstances)
-- Fixed is owned
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.