- 基本は迷ったら trait にしておけば良いと思います
- trait は一つの class に複数 mixin できますが、class は一つしか継承できません
- つまり、trait であれば mixin される class を気にしなくてよいですが、 abstract class にした場合は、extends される class が他に継承したい物が無いか気にする必要があります
- trait はコンストラクタを持つ事ができませんが、abstract class はコンストラクタを持つ事ができます
- 従って、型引数に制約をつけたい時や、共通のフィールドの初期化などがある場合は、abstract class にすると楽な場合があります。
- 以下に具体例を示します。良くある Java の enum を Scala で定義する場合の例です。
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 java.io.File | |
import scala.io.Source | |
import scala.util.matching.Regex | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input.{Position, NoPosition} | |
sealed abstract class Insn extends ( CED => CED ){ | |
val pos:Position | |
} | |
case class App( m:Int, n:Int, pos:Position ) extends Insn{ |
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
diff -c sl/sl.c sl_kq/sl.c | |
*** sl/sl.c 1998-07-22 23:01:01.000000000 +0900 | |
--- sl_kq/sl.c 2011-12-02 21:34:09.540165908 +0900 | |
*************** | |
*** 33,73 **** | |
#include "sl.h" | |
int ACCIDENT = 0; | |
int LOGO = 0; | |
int FLY = 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
import java.io.File | |
import scala.io.Source | |
import scala.util.matching.Regex | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input.{Position, NoPosition} | |
sealed abstract class Insn extends ( CED => CED ){ | |
val pos:Position | |
} | |
case class App( m:Int, n:Int, pos:Position ) extends Insn{ |
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
@charset "utf-8"; | |
/* | |
* このファイルを編集して、profile-directory/chrome/userContent.css | |
* としてコピーしてください。 | |
*/ | |
/* | |
* このファイルは、表示するすべての Web ページにスタイルを適用するのに使用 | |
* することができます。 | |
* !important なし規定は、Web ページ作者が何かを設定した場合には、作者の |
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
@rem =========================================================================== | |
@rem stdout yyyy.M.D format, work in standard environment | |
@rem @license CC0 1.0 (Univ. PD) https://creativecommons.org/publicdomain/zero/1.0/ | |
@rem @author noromanba (http://flavors.me/noromanba) | |
@rem @homepage https://gist.github.com/1866433 | |
@rem =========================================================================== | |
:: c.f. http://ptech.g.hatena.ne.jp/noromanba/20120717 | |
@echo off | |
cd %~dp0 |
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
#!/usr/bin/gawk -f | |
#http://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html | |
BEGIN { | |
gcc_cmd="gcc -Q --help=warnings,^joined,^undocumented"; | |
w_lv[0] = ""; | |
w_lv[1] = "-Wall"; | |
w_lv[2] = "-Wall -Wextra"; | |
for(i = 0;i < 3;i++){ | |
cmdln = sprintf("%s %s",gcc_cmd,w_lv[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
#!/bin/bash | |
function printit { | |
echo "This is from an embedded function: $1" | |
} | |
function printthat { | |
echo "This is the first line." | |
$1 $2 | |
echo "This is the third line." |
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
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.Text; | |
using Microsoft.CodeAnalysis.CSharp; | |
using Microsoft.CodeAnalysis.CSharp.Syntax; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; |
OlderNewer