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
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE FunctionalDependencies #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| import Control.Applicative (liftA2) | |
| type Polynomial = [Rational] | |
| instance Num a => Num [a] where |
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
| {-# LANGUAGE StandaloneDeriving #-} | |
| {-# LANGUAGE BangPatterns #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE LambdaCase #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE TupleSections #-} | |
| {-# LANGUAGE DeriveGeneric #-} | |
| import qualified Data.OrdPSQ as Map |
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
| {-# LANGUAGE TupleSections, GADTs, DeriveFunctor, DeriveFoldable #-} | |
| import Control.Applicative | |
| import Data.Foldable (traverse_,toList) | |
| import Test.QuickCheck | |
| import qualified Data.List | |
| import Control.Monad.State | |
| -------------------------------------------------------------------------------- |
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
| import Data.Tuple (swap) | |
| import Data.Bool (bool) | |
| type N = Integer | |
| myhill :: (N -> N) -> (N -> N) -> [(N,N)] | |
| myhill f g = iterate False 0 [] | |
| where | |
| iterate b x m | |
| | x `elem` map snd n = iterate (not b) z m |
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
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| import Control.Comonad.Cofree | |
| import Data.Map.Strict (Map) | |
| import qualified Data.Map.Strict as Map | |
| import Control.Lens hiding ((:<)) | |
| import Data.Foldable | |
| import Data.Maybe |
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
| {-# LANGUAGE GADTs, ScopedTypeVariables, RankNTypes #-} | |
| import Data.List (unfoldr) | |
| nextLexPerm :: Ord a => [a] -> Maybe [a] | |
| nextLexPerm (x:y:xs) | |
| | Just ys <- nextLexPerm (y:xs) = Just (x:ys) | |
| | x < y = Just (go x y xs []) | |
| where | |
| go i j (k:xs) ys | i < k = go i k xs (j:ys) |
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
| primes : ∀ n → List (Fin n) | |
| primes zero = [] | |
| primes (suc zero) = [] | |
| primes (suc (suc zero)) = [] | |
| primes (suc (suc (suc m))) = sieve (tabulate (just ∘ Fin.suc)) | |
| where | |
| cross-off : ∀ {n} → Fin _ → Vec (Maybe _) n → Vec (Maybe _) n | |
| sieve : ∀ {n} → Vec (Maybe (Fin (2 + m))) n → List (Fin (3 + m)) | |
| sieve [] = [] |
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
| import Data.List (unfoldr, partition) | |
| import Data.Maybe (catMaybes) | |
| import Criterion.Main (defaultMain, env, bgroup, bench, nf) | |
| import System.Random (randomIO) | |
| import Control.Monad (replicateM) | |
| groupOn :: Eq k => (a -> k) -> [a] -> [(k, [a])] | |
| groupOn k = unfoldr f . map (\x -> (k x, x)) | |
| where | |
| f [] = Nothing |
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
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| import Control.Applicative | |
| data Free f a where | |
| Pure :: a -> Free f a | |
| App :: f (a -> b) -> Free f a -> Free f b | |
| instance Functor f => Functor (Free f) where |
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
| {-# LANGUAGE BangPatterns #-} | |
| {-# LANGUAGE TemplateHaskell #-} | |
| {-# LANGUAGE ViewPatterns, PatternSynonyms #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving, DerivingVia, DerivingStrategies #-} | |
| {-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-} | |
| import Data.Bits | |
| import Data.Bool | |
| import Test.QuickCheck hiding ((.&.)) | |
| import Control.Applicative |
NewerOlder