This file contains hidden or 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 { curry } from 'ramda' | |
import React from 'react' | |
import { withStateHandlers } from 'recompose' | |
import styled, { css } from 'styled-components' | |
const initialState = { retryCount: 1 } | |
const stateHandlers = { | |
reload: ({ retryCount }) => _ => ({ retryCount: retryCount + 1 }) | |
} |
This file contains hidden or 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 { STATUSES } from '@/constants' | |
import withUserInformation from '@/hocs/withUserInformation' | |
import { identity } from 'ramda' | |
import { branch, compose, renderComponent } from 'recompose' | |
import LoginPage from '../routes/login' | |
const privateComponent = branch( | |
({ loginStatus }) => loginStatus === STATUSES.SUCCESSED, | |
identity, | |
renderComponent(LoginPage) |
This file contains hidden or 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
#include <iostream> | |
using namespace std; | |
// 罗马数字共有 7 个,即 I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和 | |
// M(1000) | |
string transform(string accu, int n) { | |
if (n == 0) | |
return accu; | |
int ms = n / 1000; |
This file contains hidden or 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
{ | |
(* short names for important modules *) | |
module L = Lexing | |
module B = Buffer | |
type token = | |
| STR of string | |
| INT of int | |
| ID of string | |
| PLUSEQ |
This file contains hidden or 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
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 = |
This file contains hidden or 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
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 |
This file contains hidden or 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
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] |
This file contains hidden or 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
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) |
This file contains hidden or 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 TupleSections #-} | |
module Exe where | |
class Fluffy f where | |
furry :: (a -> b) -> f a -> f b | |
-- Exercise 1 | |
-- Relative Difficulty: 1 | |
instance Fluffy [] where |
This file contains hidden or 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 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 |