| data Bool { T, F } | |
| data Nat { Z, S(n: Nat) } | |
| def (n1: Nat).eq(n2: Nat): Bool { | |
| Z => n2.match { | |
| Z => T, | |
| S(_) => F, | |
| }, | |
| S(n1) => n2.match { |
| data P = R | L | Seq P P | Loop P | |
| data Tape = Tape [Int] Int [Int] | |
| empty :: Tape | |
| empty = Tape (repeat 0) 0 (repeat 0) | |
| left :: Tape -> Tape | |
| left (Tape (l:ls) v rs) = Tape ls l (v:rs) |
| (** This is a demonstration of implementing interpreters in an extensible way | |
| that offers a partial solution to the expression problem. The idea is that | |
| the language can be extended with more features after the fact, without | |
| altering previous definitions. It also has the benefit of grouping the | |
| related extensions to the syntax and semantic domains together with the | |
| relevant evaluation rules in a per-feature way. | |
| This approach used is similar to the one described by Matthias Blume in | |
| {{:https://www.microsoft.com/en-us/research/video/records-sums-cases-and-exceptions-row-polymorphism-at-work/} | |
| Records, sums, cases, and exceptions: Row-polymorphism at work}. |
| /////////////////////////////////////////////////////////////////////////////// | |
| // ABOUT: A unity Shader .cginc to draw numbers in the fragment shader | |
| // AUTHOR: Freya Holmér | |
| // LICENSE: Use for whatever, commercial or otherwise! | |
| // Don't hold me liable for issues though | |
| // But pls credit me if it works super well <3 | |
| // LIMITATIONS: There's some precision loss beyond 3 decimal places | |
| // CONTRIBUTORS: yes please! if you know a more precise way to get | |
| // decimal digits then pls lemme know! | |
| // GetDecimalSymbolAt() could use some more love/precision |
| class BritishNaming(type): | |
| def __new__(mcs, *args): | |
| cls = super().__new__(mcs, *args) | |
| cls.__init__ = cls.__innit__ | |
| return cls | |
| class MyBritishClass(metaclass=BritishNaming): | |
| def __innit__(self): | |
| print("I am british now ig") |
\b(?:(?<fizzbuzz>(?:(?:[369]|[258][0369]*[147]|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*(?:[28]|[147][0369]*[147]))*(?:0|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*5))+)|(?<buzz>\d*[05])|(?<fizz>(?:[0369]|[258][0369]*[147]|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*(?:[258]|[147][0369]*[147]))+))\binsanity, as i'd like to call it. although it isn't fizzbuzz per se, it's the best you can get with regex. here's a regexr link to it with sample text.
this matches a number (within word boundaries) if it falls under any of the three groups:
fizzbuzz, which picks up numbers divisible by both 3 and 5, i.e. 15;buzz, which picks up numbers divisible by 5; andfizz, which picks up numbers divisible by 3.
This is based on a neat little post that I saw on Simon Frankau‘s blog that I thought I’d provide a few more details on, as well as bringing it to a wider audience. Some higher-level data structures in object-oriented programming languages have dynamic memory allocation. This is used to create objects (usually things that behave like lists) that can grow and shrink as the program executes. When initializing a regular array in C or Java, you have to specify the size of the array on creation, for example with
int myArray[] = new int[10];
| {-# LANGUAGE UndecidableInstances #-} | |
| module Hylo where | |
| -- An attempt to derive a hylomorphism from the type signature (at the time of | |
| -- writing I don't recall ever seeing the implementation of one). | |
| type Algebra f a = f a -> a | |
| type Coalgebra f a = a -> f a |
The originality of these Gists varies drastically. Most are inspired by the work of others, in that case, all merit goes to the original authors. I have linked everything used as reference material on the Gists themselves.