Skip to content

Instantly share code, notes, and snippets.

View Shuumatsu's full-sized avatar

为世人降下祝福 Shuumatsu

View GitHub Profile
#[derive(Debug)]
struct SelfRef {
text: String,
ptr: *const String,
}
impl SelfRef {
fn new(txt: &str) -> Self {
let text = String::from(txt);
let mut ret = SelfRef { text, ptr: std::ptr::null() };
@Shuumatsu
Shuumatsu / riscv.md
Created December 24, 2020 07:51 — forked from cb372/riscv.md
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

Section BHK_interpretable.
Hypotheses P Q R:Prop.
Theorem bot_to_p: False -> P.
Proof. intros. contradiction. Qed.
Theorem neglect_Q: P -> Q -> P.
Proof. intros. assumption. Qed.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
module Step where
import qualified Data.Map.Strict as Map
import Control.Monad.State.Strict (StateT(..))
import Control.Applicative
{-# LANGUAGE TupleSections #-}
module Exe where
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
-- Relative Difficulty: 1
instance Fluffy [] where
@Shuumatsu
Shuumatsu / StateMonad.hs
Created June 5, 2019 03:59
State monad as composition of (a ->) & (, s)
newtype State s a = State { runState :: s -> (a, s) }
instance Functor (State s) where
-- fmap f st = State
-- $ \s -> let (a, s') = runState st s
-- in (f a, s')
-- fmap f st = State $ fmap (fmap f) (runState st)
fmap f st = State $ (.) (\(a, s) -> (f a, s)) (runState st)
fmap f st = State $ (\g x -> (\(a, s) -> (f a, s)) $ g x) (runState st)
fmap f st = State $ (\x -> (\(a, s) -> (f a, s)) $ (runState st) x)
open Base
module Make (Eq : sig
type t
val equal : t -> t -> bool
end) =
struct
type operation = Delete of int | Insert of int [@@deriving show]
open Base
module Make (Comparable : Comparable.S) = struct
let sort_into_piles list =
let piles = Array.create ~len:(List.length list) [] in
let bsearch len elem =
let rec aux lo hi =
if lo > hi then lo
else
let mid = (lo + hi) / 2 in
module PrioQueue = struct
type priority = int
type 'a queue = Empty | Node of priority * 'a * 'a queue * 'a queue
let empty = Empty
let is_empty = function Empty -> true | _ -> false
let rec insert queue prio elt =
@Shuumatsu
Shuumatsu / tokenizer.mll
Created April 10, 2019 12:43 — forked from lindig/tokenizer.mll
Some Scanning Recipes for OCamlLex
{
(* short names for important modules *)
module L = Lexing
module B = Buffer
type token =
| STR of string
| INT of int
| ID of string
| PLUSEQ