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 scala.annotation.tailrec | |
import scala.language.higherKinds | |
sealed trait Freer[F[_], A] { | |
def map[B](f: A => B): Freer[F, B] = flatMap(a => Pure(f(a))) | |
def flatMap[B](f: A => Freer[F, B]): Freer[F, B] = | |
this match { | |
case Pure(a) => f(a) | |
case Impure(fa, g) => Impure(fa, g :+ f) | |
} |
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 scala.reflect.macros.Context | |
import scala.util.matching.Regex | |
import java.util.regex.PatternSyntaxException | |
object Macros{ | |
implicit class RegexContext(val c: StringContext) { | |
def r(): Regex = macro regexImpl | |
} |
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
$ scala rpnparser.scala | |
1 1 + = 2 | |
3 1 - = -2 | |
3 2 * = 6 | |
8 2 / = 0 | |
2 (2 2 +) + = 6 | |
2 2 2 + + = 6 | |
(2 2 +) 2 + = 6 | |
(2 2 +) (4 2 +) * = 24 | |
((2 2 +) (4 2 +) *) 2 / = 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
Inductive even : nat -> Prop := | |
| even_O : even 0 | |
| even_S : forall n, odd n -> even (S n) | |
with odd : nat -> Prop := | |
| odd_S : forall n, even n -> odd (S n). | |
Scheme even_mut := Induction for even Sort Prop | |
with odd_mut := Induction for odd Sort Prop. | |
Theorem daigakuseinosuugakuryoku : forall n m, |
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
fizzbuzz = zipWith max (map show [0..]) fb | |
where | |
fb = zipWith (++) f b | |
f = cycle ["Fizz", "", ""] | |
b = cycle ["Buzz", "", "", "", ""] | |
main = mapM_ putStrLn $ tail $ fizzBuzz |