Skip to content

Instantly share code, notes, and snippets.

View tuohuang-li's full-sized avatar
:octocat:

Tuohuang Li tuohuang-li

:octocat:
  • @ Unimelb
  • Melbourne
View GitHub Profile
@tuohuang-li
tuohuang-li / Tree.hs
Created June 5, 2022 13:07 — forked from Kedrigern/Tree.hs
Implementation of binary search tree in Haskell
{- Implementation of BST (binary search tree)
Script is absolutly free/libre, but with no guarantee.
Author: Ondrej Profant -}
import qualified Data.List
{- DEF data structure -}
data (Ord a, Eq a) => Tree a = Nil | Node (Tree a) a (Tree a)
deriving Show
@tuohuang-li
tuohuang-li / RailroadMonad.hs
Created June 5, 2022 13:05 — forked from davenportw15/RailroadMonad.hs
An example of "railroad" error handling
module Result where
import Control.Monad
import Data.Monoid
data Result a b
= Failure a
| Success b
deriving (Show)
@tuohuang-li
tuohuang-li / HashMap.hs
Created June 5, 2022 12:54 — forked from davenportw15/HashMap.hs
A hashmap implementation in Haskell backed by a binary tree.
module HashMap where
import Prelude hiding (lookup)
-- | HashMap backed by a binary tree. Most operations are O(log(n))
data HashMap k v = EmptyMap | Map (k, v) (HashMap k v) (HashMap k v) deriving (Read, Show)
-- | Apply fmap over all values
instance (Ord k) => Functor (HashMap k) where