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, DeriveFoldable, KindSignatures, ScopedTypeVariables #-} | |
| module Main where | |
| import GHC.TypeLits | |
| data Array (n :: Nat) a = Array [a] | |
| instance Foldable (Array n) where | |
| foldr f x (Array xs) = foldr f x 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
| {- | |
| A Haskell solution to the word splitting problem. | |
| http://blogs.perl.org/users/ingy_dot_net/2015/11/perl-regular-expression-awesomeness.html | |
| -} | |
| import Data.Foldable ( asum, for_ ) | |
| import Text.Regex.Applicative ( (=~), many, string ) | |
| main :: IO () | |
| main = do |
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
| //////////////////////////////////////////////////////////////////////////////// | |
| // Optional | |
| abstract class Optional<A> {} | |
| class None extends Optional<A> {} | |
| class Some<A> extends Optional<A> { | |
| A value; | |
| } |
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
| CFLAGS = -O1 | |
| main: main.o b.o |
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 Config = Config { config_isDebug :: Bool } | |
| data Worker a = Worker a | |
| data Work = DebugInfo | Payload | |
| instance MonadReader Config Worker | |
| instance MonadWriter Work Worker | |
| -- | Make DebugInfo if debug is enabled. | |
| debugInfo :: MonadReader Config m => m (Maybe Work) | |
| debugInfo = do | |
| isDebug <- asks config_isDebug |
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 System.IO.Unsafe | |
| heavy y = unsafePerformIO $ do | |
| putStrLn "heavy" | |
| return y | |
| f1 x = heavy 10 + x | |
| f2 x = let y = heavy 10 in y + x |
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 Logic.Deduction where | |
| modusPonens :: (a -> b) -> a -> b | |
| modusPonens = id | |
| transitivity :: (b -> c) -> (a -> b) -> a -> c | |
| transitivity = (.) | |
| cons1 :: (a -> c) -> (b -> c) -> Either a b -> c | |
| cons1 f _ (Left x) = f x |
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
| -- original code is written by https://github.com/klapaucius | |
| {-# OPTIONS -Wall -Werror #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| module Main (main) 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 LambdaCase #-} | |
| import Data.Ratio (denominator, numerator) | |
| data Expr = Number Rational | Paren Arith | |
| instance Show Expr where | |
| show = \case | |
| Number n -> case denominator n of | |
| 1 -> show (numerator n) | |
| _ -> show n |
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
| {-# OPTIONS -Wall -Werror #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE TemplateHaskell #-} | |
| import Control.Applicative ((<|>)) | |
| import Control.Monad (void) | |
| import Test.QuickCheck | |
| import Text.Show.Functions () |