This file contains 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
def cons(x, lis): | |
return lambda t: x if t else lis | |
def nil(): | |
return None | |
def foldr(fn, lis, init): | |
if lis is None: | |
return init | |
head = lis(True) |
This file contains 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
takeExactly :: Int -> [a] -> Maybe [a] | |
takeExactly 0 _ = Just [] | |
takeExactly n [] = Nothing | |
takeExactly n (x:xs) = (x:) <$> takeExactly (n - 1) xs | |
windows :: Int -> [a] -> [[a]] | |
windows n xs = case takeExactly n xs of | |
Nothing -> [] | |
Just window -> window:windows n (tail xs) |
This file contains 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
perverse : {a : Type} -> a -> a | |
perverse {a = Integer} x = x + 1 | |
perverse {a = String} x = "hello " <+> x | |
perverse {a = _} x = x | |
main : IO () | |
main = do | |
printLn $ perverse 5 | |
printLn $ perverse "world" | |
printLn $ perverse True |
This file contains 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 requests | |
import sys | |
from bs4 import BeautifulSoup # type: ignore | |
from bs4.element import Tag, NavigableString # type: ignore | |
from typing import Callable, Dict, List | |
def retrieve(url: str) -> BeautifulSoup: | |
rq = requests.get(url) | |
rq.encoding = 'utf-8' |
This file contains 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
// this is annoying in every language with a const-like | |
#include <cstddef> | |
#include <iostream> | |
#include <stdexcept> | |
#include <type_traits> | |
// just duplicate... | |
class A { | |
int xs_[10] = { }; |
This file contains 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> | |
#include <memory> | |
#include <vector> | |
struct base { | |
virtual ~base() = default; | |
}; | |
struct capability1 { | |
virtual void do_capability1() = 0; |
This file contains 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 <cstddef> | |
#include <iostream> | |
template<std::size_t N> | |
struct symbol { | |
char name[N]; | |
constexpr symbol(const char (&str)[N]) noexcept | |
{ | |
for (std::size_t i = 0; i < N; ++i) |
This file contains 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> | |
/* are concept constraint violations like SFINAE "errors", or like, uh... | |
* ... the other kind? | |
* they're like SFINAE errors! constraint violations take function templates | |
* out of consideration for overloading, but are not errors. | |
*/ | |
template<class T> | |
concept fugastic = requires { |
This file contains 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
#![feature(raw)] | |
// tested with rustc 1.49.0-nightly (91a79fb29 2020-10-07) | |
use std::{ | |
any::{Any, TypeId}, | |
collections::HashMap, | |
mem, | |
raw::TraitObject, | |
}; |
This file contains 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
#![feature(const_generics, const_evaluatable_checked)] | |
#![allow(incomplete_features)] | |
// tested with rustc 1.49.0-nightly (91a79fb29 2020-10-07) | |
fn append<T: Copy + Default, const N: usize, const M: usize>( | |
xs: &[T; N], ys: &[T; M]) -> [T; N + M] { | |
let mut result = [T::default(); N + M]; | |
result[..N].copy_from_slice(&xs[..]); | |
result[N..].copy_from_slice(&ys[..]); |