This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [In Haskell] | |
| foldr :: (a -> b -> b) -> b -> [a] -> b | |
| foldr = ...... | |
| (example) | |
| foldr (+) 0 [a,b,c] = a + (b + (c + 0)) | |
| [In C++] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Breaking first-class-instances | |
| {-# | |
| LANGUAGE | |
| TemplateHaskell, | |
| RankNTypes, | |
| TypeFamilies, | |
| KindSignatures, | |
| FlexibleInstances, | |
| ConstraintKinds | |
| #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {- | |
| 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 == [])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Lib | |
| ( largestPowersInt ) where | |
| class Eq a => Iterable a where | |
| zer :: a | |
| inc :: a -> a | |
| dec :: a -> a | |
| instance Iterable Int where | |
| zer = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |