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
#include <iostream> | |
using namespace std; | |
struct Point { | |
double x, y; | |
}; | |
string to_string(Point p) { | |
return string("Point{") + to_string(p.x) + ", " + to_string(p.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
{-# LANGUAGE NamedFieldPuns #-} | |
{-# LANGUAGE RecordWildCards #-} | |
import Data.IORef | |
type ItemPtr a = IORef (Maybe (Item a)) | |
data Item a = Item{value :: a, prev, next :: !(ItemPtr a)} | |
newtype DLList a = DLList (IORef (Maybe (Item a, Item 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 LambdaCase #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module ConIndex (conIndex) where | |
import Data.List (findIndex) | |
import Language.Haskell.TH (Con (..), Dec (DataD), ExpQ, | |
Info (DataConI, TyConI), Name, ParentName, | |
integerL, litE, reify) |
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
#!/usr/bin/env stack | |
-- stack --resolver=lts-8.11 script --package=union | |
{-# OPTIONS -Wall -Werror #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE NamedFieldPuns #-} | |
{-# LANGUAGE TypeApplications #-} |
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
-- stack runhaskell | |
{-# OPTIONS -Wall -Werror #-} | |
{-# LANGUAGE LambdaCase #-} | |
import Control.Monad.State | |
import Data.IntMap | |
import Data.Woot | |
import Text.Show.Pretty |
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 () |
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
-- 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
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
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 |