Skip to content

Instantly share code, notes, and snippets.

raichoo raichoo

Block or report user

Report or block raichoo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@raichoo
raichoo / Wat.hs
Created Sep 7, 2017
Data.Text rewrite rules fun.
View Wat.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (length, filter)
import Data.Text
-- Turn on optimizations (-O) to make this `False`
wat :: Text -> Bool
wat x = length (filter (== ',') x) == 1
@raichoo
raichoo / Test.hs
Created Sep 5, 2017
Playing with capabilities.
View Test.hs
module Main where
import Control.Monad
import Control.Concurrent
import Text.Printf
import Foreign.C.Types
foreign import ccall safe "getchar" c_getchar :: IO CChar
View whoopwhoop.lua
function f (x)
print("f: " .. x)
return g (x + 1)
end
function g (x)
print("g: " .. x)
return f (x + 1)
end
View Puzzler.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
module Main where
data Test = Test
{ testFoo :: Int
, testBar :: Bool
}
@raichoo
raichoo / summer.hs
Created Sep 30, 2016
Haskell Example
View summer.hs
module Assign where
import Data.IORef
mkSummer :: IO (Int -> Int -> IO Int)
mkSummer = do
ref <- newIORef 0
return $ \x y -> do
val <- readIORef ref
@raichoo
raichoo / ReaderEx.hs
Created Aug 26, 2016
Example where Reader is helpful.
View ReaderEx.hs
module Main where
-- ReaderT is a little more useful as an example
-- think of it as Reader that can also do IO using
-- the `lift` function.
import Control.Monad.Reader
import Text.Printf
type Connection = ()
View AesonTag.hs
{-# LANGUAGE DeriveGeneric #-}
module AesonTag where
import Data.Aeson
import GHC.Generics
data Foo
= Bar Int
| Quux { tag :: Bool }
@raichoo
raichoo / SleepSort.hs
Created Jul 20, 2016
Sleepsort implementation in Haskell
View SleepSort.hs
module Main where
import Data.Foldable
import Control.Concurrent
import Control.Monad
import System.IO.Unsafe
sleepSort :: [Int] -> [Int]
View segfault.idr
module Main
(>>) : Monad m => m a -> m b -> m b
ma >> mb = ma >>= \_ => mb
forever : Monad m => m a -> m a
forever x = x >> forever x
main : IO ()
main = forever (putStrLn "foo")
@raichoo
raichoo / PlusZero.hs
Last active May 10, 2016
Oh… this works.
View PlusZero.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
module PlusZero where
import Data.Type.Equality
data Nat
= Zero
You can’t perform that action at this time.