Skip to content

Instantly share code, notes, and snippets.

View raichoo's full-sized avatar

raichoo raichoo

View GitHub Profile
@raichoo
raichoo / notes.hs
Created September 11, 2021 12:19
Quick and dirty scale learning script
module Main where
import Control.Monad
import Data.List
import System.Random
import Data.Map (Map)
import Data.Bool
import Text.Read
import Data.Maybe
import qualified Data.Map as Map
@raichoo
raichoo / Wat.hs
Created September 7, 2017 15:44
Data.Text rewrite rules fun.
{-# 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 September 5, 2017 14:17
Playing with capabilities.
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
function f (x)
print("f: " .. x)
return g (x + 1)
end
function g (x)
print("g: " .. x)
return f (x + 1)
end
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
module Main where
data Test = Test
{ testFoo :: Int
, testBar :: Bool
}
@raichoo
raichoo / summer.hs
Created September 30, 2016 16:53
Haskell Example
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 August 26, 2016 22:56
Example where Reader is helpful.
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 = ()
{-# LANGUAGE DeriveGeneric #-}
module AesonTag where
import Data.Aeson
import GHC.Generics
data Foo
= Bar Int
| Quux { tag :: Bool }
@raichoo
raichoo / SleepSort.hs
Created July 20, 2016 19:24
Sleepsort implementation in Haskell
module Main where
import Data.Foldable
import Control.Concurrent
import Control.Monad
import System.IO.Unsafe
sleepSort :: [Int] -> [Int]
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")