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 TemplateHaskell, MultiParamTypeClasses, TypeSynonymInstances #-} | |
| {-# LANGUAGE FlexibleInstances, GADTs, FlexibleContexts #-} | |
| import Control.Monad.State | |
| import Control.Lens | |
| import Control.Monad.Operational.TH (makeSingletons) | |
| import Control.Monad.Operational.Mini | |
| import Data.Functor.Product | |
| data Pattern p q x where | |
| Hook :: Either (State p ()) (State q ()) -> Pattern p q () |
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 TemplateHaskell, RankNTypes, GADTs, FlexibleContexts #-} | |
| import Control.Lens | |
| import Control.Monad.State | |
| import Control.Monad.Operational.Mini | |
| import Control.Monad.Operational.TH (makeSingletons) | |
| import Data.Maybe (fromJust) | |
| data Pattern p q x where | |
| Hook :: Lens' q a -> State a () -> Pattern p q () | |
| Pick :: Lens' q a -> Pattern p q 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
| {-# LANGUAGE GADTs, TemplateHaskell, FlexibleContexts #-} | |
| import Control.Arrow | |
| import Data.List | |
| import Control.Monad.Operational.Mini | |
| import Control.Monad.Operational.TH (makeSingletons) | |
| import Control.Monad.State | |
| data Pattern p q x where | |
| GetLocal :: Pattern p q p | |
| PutLocal :: p -> Pattern p q () |
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, DataKinds, KindSignatures, TypeOperators, ConstraintKinds #-} | |
| {-# LANGUAGE TypeFamilies, UndecidableInstances, FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| import GHC.Prim (Constraint) | |
| import Data.Typeable | |
| type family All (cx :: * -> Constraint) (xs :: [*]) :: Constraint | |
| type instance All cx '[] = () | |
| type instance All cx (x ': xs) = (cx x, All cx 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
| {-# LANGUAGE DataKinds, GADTs, KindSignatures, FlexibleInstances, FlexibleContexts, TypeFamilies #-} | |
| import Control.Applicative | |
| data Nat = Zero | Succ Nat | |
| type family Plus (n :: Nat) (m :: Nat) :: Nat | |
| type instance Plus (Succ n) m = Succ (Plus n m) | |
| type instance Plus Zero m = m | |
| data LengthList n a where | |
| Nil :: LengthList Zero 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
| {-# LANGUAGE GADTs, DataKinds, TypeFamilies, ConstraintKinds, TypeOperators, UndecidableInstances #-} | |
| import GHC.Prim (Constraint) | |
| import Data.Ratio ((%)) | |
| type family All (cx :: * -> Constraint) (xs :: [*]) :: Constraint | |
| type instance All cx '[] = () | |
| type instance All cx (x ': xs) = (cx x, All cx xs) | |
| data HList (as :: [*]) 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
| sqRootPair :: Int -> [(Int, Int)] | |
| sqRootPair n = filter (\(x,y) -> x^2 + y^2 == n) | |
| [(x,y) | x <- [1..n], y <- [1..n], x < y, x^2 < n, y^2 < n] | |
| show' :: [(Int, Int)] -> String | |
| show' ns = ((\(x,y) -> show $ x^2 + y^2) $ ns !! 0) ++ " :" ++ show ns | |
| main = do | |
| mapM_ (putStrLn . show') $ filter (\x -> length x /= 0) [sqRootPair n | n <- [1,3..]] |
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 TypeOperators, MultiParamTypeClasses, FlexibleInstances #-} | |
| {-# LANGUAGE FlexibleContexts, TypeFamilies, UndecidableInstances #-} | |
| import Control.Comonad | |
| data BigCrunch = BigCrunch deriving (Show) | |
| data f :> g = f :> g deriving (Show) | |
| infixr :> | |
| class Universal c a where | |
| runUniverse :: c -> 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.Functor.Free | |
| import Data.Monoid | |
| type CSV a = Free Monoid [a] | |
| cell :: a -> CSV a | |
| cell = unit . return | |
| fromList :: [a] -> CSV a | |
| fromList = unit |
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 FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-} | |
| {-# LANGUAGE FlexibleContexts, UndecidableInstances #-} | |
| import Data.Bifunctor | |
| import Data.Biapplicative | |
| import Data.List | |
| data Tensor a b = a :*: b deriving (Show) | |
| class ShowAll c where | |
| toList :: [c] |