Skip to content

Instantly share code, notes, and snippets.

View mather's full-sized avatar
🐻
friendly bear

Eisuke Kuwahata mather

🐻
friendly bear
View GitHub Profile
class A
class B extends A
class C extends A
def isType[T <: A](a: A) = a.isInstanceOf[T]
// <console>:9: warning: abstract type T is unchecked since it is eliminated by erasure
// def isType[T <: A](a: A) = a.isInstanceOf[T]
// ^
// isType: [T <: A](a: A)Boolean
@mather
mather / Calculator.scala
Created February 23, 2015 02:32
Calculator Sample
// "sealed" : Declare that no other subclass except this file. This helps compiler to verify loss of pattern.
sealed trait Expression {
def a: Int
def b: Int
}
case class Addition(a: Int, b: Int) extends Expression
case class Subtraction(a: Int, b: Int) extends Expression
case class Multiply(a: Int, b: Int) extends Expression
case class Division(a: Int, b: Int) extends Expression
@mather
mather / elemCount.hs
Last active April 27, 2016 00:26
複数のアプローチでリスト内の同一要素の数を数える
module ElemCount where
import Data.List
-- | for empty list
--
-- >>> elemCountOrd []
-- []
--
-- | count the same element
import Data.List
main = do
l <- fmap toInt $ getLine -- 標準入力からLを読み込む
n <- fmap toInt $ getLine -- 標準入力からNを読み込む(使わない
bars <- fmap (fmap toInt . lines) $ getContents -- 残りのリストを取得
print (sum $ fmap (findTripleSum l) $ tails bars) -- tails で部分リストを順番に調べる
-- Int化
toInt :: [Char] -> Int
@mather
mather / TraitLazyExam.scala
Last active August 29, 2015 14:25
Scalaのトレイトで抽象メンバとそれを参照する`lazy val`のあるときに、`lazy val`を参照する側にも常に`lazy`であることを要求してしまう例
trait Hoge {
protected val hoge: String
lazy val l = hoge.length
}
trait Piyo {
this: Hoge =>
val p = l
}
@mather
mather / .gitattributes
Last active May 18, 2018 08:42
git diff や git show で複数のエンコードのファイルを扱う ref: https://qiita.com/mather314/items/a6b4bad59e2edd659dd4
*.txt diff=sjis
@mather
mather / bubble_sort.hs
Last active April 27, 2016 00:15
バブルソート in Haskell
module BubbleSort where
-- |
-- Bubble Sort
--
-- >>> bubbleSort [1,2,3]
-- [1,2,3]
--
-- >>> bubbleSort [2,3,1]
-- [1,2,3]
@mather
mather / BMI.elm
Created November 29, 2016 08:25
BMI計算機 by Elm 0.18
import Html exposing (..)
import Html.Attributes as A exposing (type_, value, min, max, step, disabled)
import Html.Events exposing (onInput)
import Json.Decode exposing (decodeString, float)
main =
Html.beginnerProgram
{ model = initialModel
, view = view
, update = update
@mather
mather / README.md
Created April 16, 2017 08:32
南九州ソフトウェア設計Labo vol.2 ハンズオン課題

南九州ソフトウェア設計ハンズオン

https://sk-design-labo.connpass.com/event/53851/

課題

  • オブジェクト指向
  • ピザを購入する流れを記述
    • 1500円のピザを購入
  • -800円のキャンペーンが適用されたりされなかったり
@mather
mather / monoid.elm
Last active November 15, 2017 09:29
ElmでMonoidを作ってみた?
module Monoid exposing (..)
import Html exposing (text)
main = text <| toString <| sum [1,2,3]
type alias Monoid a =
{ empty : a
, append : a -> a -> a
}