This file contains 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 Data.List | |
clockwise :: (Int, Int) -> (Int, Int) -> (Int, Int) -> Bool | |
clockwise (x1, y1) (x2, y2) (x3, y3) = (x1 - x2) * (y3 - y2) - (x3 - x2) * (y1 - y2) < 0 | |
-- Graph == [(Int, Int)] | |
convexHull :: Graph -> Graph | |
convexHull = (uncurry (++)) . (upperHalf &&& lowerHalf) . sort | |
where |
This file contains 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
function solve(t,n){return ("0".repeat(n)+(t^t>>1).toString(2)).slice(-n)} |
This file contains 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 T a = T {element :: a, element2 :: a, element3 :: String} deriving (Show) | |
class F a where | |
mes :: a -> String | |
instance F Int where mes _ = "Int" | |
instance F Double where mes _ = "Double" | |
mkDefaultT :: (F a, Num a) => a -> T a | |
mkDefaultT x = T x x (mes x) |
This file contains 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
nat(0). | |
nat(X1) :- nat(X), X1 is X + 1. | |
pair_of_nats(X, Y) :- nat(X), nat(Y). | |
(0 step) | |
pair_of_nats(X, Y). | |
(1 step) | |
nat(X), nat(Y). |
This file contains 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
[<cons <card _ $n> | |
<cons <card _ ,(- n 1)> | |
<cons <card _ ,(- n 2)> | |
<cons <card _ ,(- n 3)> | |
<cons <card _ (& ?(lt? $ 11) ,(- n 4))> ;; ここだけ修正: ,(- n 4) → (& ?(lt? $ 11) ,(- n 4)) | |
<nil>>>>>> | |
<Straight>] |
This file contains 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
;; 従来のcard matcherをregular-card matcherにリネーム | |
(define $regular-card | |
(algebraic-data-matcher | |
{<card suit (mod 13)>})) | |
;; Joker入りcard matcher | |
;; (,<Joker>みたいなvalue typeは考えてない | |
;; 欲しけりゃプリミティブパターン節を一個追加すればいいと思うけど未検証) | |
(define $card | |
(matcher |
This file contains 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
;; map function | |
(define $map : [$A $B] ([(A -> B) {A}] -> {B}) | |
(lambda [$fn $xs] | |
(match xs (list something) | |
{[<nil> {}] | |
[<cons $x $rs> {(fn x) @(map fn rs)}]}))) | |
;; Ord type class | |
(type $Ordering {<Less> <Equal> <Greater>}) |
This file contains 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 TypeFamilies, KindSignatures, UndecidableInstances, DataKinds #-} | |
module TypeLevelIf where | |
import Data.Singletons.Types | |
type family Loop n :: * | |
type instance Loop a = Loop a | |
main :: IO () | |
main = do | |
let a = undefined :: If 'True Int (Loop Int) |
This file contains 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 TypeFamilies, DataKinds, KindSignatures, TypeOperators, UndecidableInstances, ScopedTypeVariables #-} | |
module Main where | |
import Data.Type.Natural | |
import Data.Proxy | |
data FB = Number Nat | Fizz | Buzz | FizzBuzz | |
type family Mod (m :: Nat) (n :: Nat) :: Nat | |
type instance Mod (S m) n = MN (S m) n (n :<<= m) |
This file contains 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 TypeFamilies, DataKinds, KindSignatures, TypeOperators, UndecidableInstances, ScopedTypeVariables #-} | |
module Main where | |
import Data.Type.Natural | |
import Data.Proxy | |
data FB = Number Nat | Fizz | Buzz | FizzBuzz | |
type family Add15 (fb :: FB) :: FB | |
type instance Add15 (Number n) = Number (n :+ N15) |
NewerOlder