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
| package ring | |
| import language.implicitConversions | |
| import language.experimental.macros | |
| import scala.{specialized => spec} | |
| import scala.reflect.makro.Context | |
| // fairly uncontroversial typeclass | |
| trait Ring[@spec(Int) A] { | |
| def zero: A |
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
| erik@vx ~/angband/angband/src $ make -f Makefile.osx | |
| CC attack.c | |
| clang: warning: not using the clang compiler for the 'powerpc' architecture | |
| llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory | |
| clang: error: gcc frontend command failed with exit code 255 (use -v to see invocation) | |
| make: *** [attack.o] Error 255 |
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
| trait Challenge[F[_]] { | |
| def map[A, B](f:A => B): F[A] => F[B] | |
| def ap[A, B](f:F[A => B]): F[A] => F[B] | |
| def foo[A, B, C](f:A => B => C): F[A] => F[B] => F[C] = { | |
| sys.error("implement me!") | |
| } | |
| } |
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
| object Implicits { | |
| implicit def xyz[A](as:Stream[A]) = new { | |
| def takeThrough(p:A => Boolean) = tt(as) | |
| def tt[A](as:Stream[A], p:A => Boolean):Stream[A] = as match { | |
| case h #:: t => Stream.cons(h, if (p(h)) tt(t) else Stream.Empty) | |
| case e => e | |
| } | |
| } | |
| } |
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
| // ok | |
| def foo0(x: Int) = | |
| x match { | |
| case 99 => 123 | |
| case _ => 999 | |
| } | |
| // not great, prefer 1-dedent for last 3 lines | |
| def foo1(x: Int) = x match { | |
| case 99 => 123 |
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
| scala> trait Foo[A] { | |
| | type Bar | |
| | def bar: Bar | |
| | | |
| | type Qux | |
| | def qux: Qux | |
| | } | |
| defined trait Foo | |
| scala> object IntHasFoo extends Foo[Int] { |
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
| object RichF { | |
| implicit class RichF1[A, Z](val f: A => Z) extends AnyVal { | |
| def map[Y](g: Z => Y): A => Y = | |
| (a: A) => g(f(a)) | |
| def flatMap[Y](g: Z => A => Y): A => Y = | |
| (a: A) => g(f(a))(a) | |
| } | |
| implicit class RichF2[A, B, Z](val f: (A, B) => Z) extends AnyVal { | |
| def map[Y](g: Z => Y): (A, B) => Y = |
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
| #!/usr/bin/python | |
| # | |
| # by Erik Osheim | |
| # | |
| # This program uses a recursive descent, LL1 parser to generate a Code object | |
| # for the given input. Code objects are pure expressions whose behavior can | |
| # only be controlled via a dictionary of strings-to-numbers provided to run. | |
| # | |
| # Syntax: | |
| # |
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
| #!/usr/bin/env python | |
| # | |
| # by Erik Osheim | |
| from pymeta.grammar import OMeta | |
| from itertools import chain | |
| import math | |
| import sys | |
| # some errors we can encounter during compilation and execution |
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
| #!/usr/bin/perl | |
| use warnings FATAL => 'all'; | |
| use strict; | |
| sub bool { return $_[0] eq "Yes" } | |
| sub num { return int($_[0]) } | |
| sub stime { | |
| my ($n) = @_; | |
| my $h = $n / 60; |