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 Text.Printf (printf) | |
data Cartesian = Cartesian { x :: Double, y :: Double } | |
instance Show Cartesian where | |
show (Cartesian x y) = printf "{ x: %.2f, y: %.2f }" x y | |
class Show a => Coordinate a where | |
toCartesian :: a -> Cartesian | |
fromCartesian :: Cartesian -> a |
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
data Term | |
= Role Role | |
| Permission Permission | |
deriving (Eq, Ord, Show) | |
data Role | |
= Admin | |
| User | |
deriving (Eq, Ord, Show) |
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
data Permission = Create | Read | Update | Delete | |
deriving (Eq, Enum, Show) | |
instance Enumerable Permission where | |
type Cardinality Permission = 4 | |
main ∷ IO () | |
main = do | |
let xs = insert Create None | |
print $ toList @Permission xs |
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 Control.Arrow ((***), (&&&)) | |
import Control.Monad (join) | |
duplicate ∷ a → (a, a) | |
duplicate = id &&& id | |
both ∷ (a → b) → (a, a) → (b, b) | |
both = join (***) |
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 UnicodeSyntax #-} | |
module IntegerSpiral where | |
import Data.Function ((&)) | |
import Text.Printf (printf) | |
import Data.VectorSpace ((^+^), (^-^)) | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import Data.List (intersperse) |
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.Sequence (Seq, pattern (:<|), pattern (:|>)) | |
import qualified Data.Sequence as Seq | |
import Data.MultiSet (MultiSet) | |
import qualified Data.MultiSet as MultiSet | |
import Data.List (unfoldr) | |
initialWindow ∷ s → [a] → Window s a | |
initialWindow s0 = (Window Seq.Empty s0) . Seq.fromList | |
data Window s a = Window (Seq a) s (Seq a) |
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 (tails, partition) | |
main = do | |
print $ maximumPairs "abcd" "adcb" | |
boundedMaximum least greatest [] = least | |
boundedMaximum least greatest (x:xs) | |
| x == greatest = x | |
| otherwise = boundedMaximum (max least x) greatest xs | |
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.Vector (Vector) | |
import qualified Data.Vector as Vector | |
import Data.Maybe (fromJust) | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
{- You're given a permutation of a set of n students, numbered from 1 to n (e.g. [1,5,3,2,4]). | |
To begin with, each student is holding their own yearbook. Each student, i, signs the notebook they're currently | |
holding before passing it to the student at index i. This repeats until every student has received their own yearbook |
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
main = do | |
n <- readLn | |
print $ fibonacci (n-1) | |
data NatF α = ZeroF | SuccF α | |
deriving Functor | |
fib :: Integer -> Integer | |
fib 0 = 0 | |
fib 1 = 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
data BinTreeF a b = Empty | Branch b a b | |
deriving Functor | |
type BinTree a = Fix (BinTreeF a) | |
divide :: Ord a => [a] -> BinTreeF a [a] | |
divide [] = Empty | |
divide (pivot:xs) = Branch lo pivot hi | |
where | |
(lo,hi) = partition (< pivot) xs |
NewerOlder