https://sk-design-labo.connpass.com/event/53851/
- オブジェクト指向
- ピザを購入する流れを記述
- 1500円のピザを購入
- -800円のキャンペーンが適用されたりされなかったり
| 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 |
| // "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 |
| 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 |
| trait Hoge { | |
| protected val hoge: String | |
| lazy val l = hoge.length | |
| } | |
| trait Piyo { | |
| this: Hoge => | |
| val p = l | |
| } |
| *.txt diff=sjis |
| module BubbleSort where | |
| -- | | |
| -- Bubble Sort | |
| -- | |
| -- >>> bubbleSort [1,2,3] | |
| -- [1,2,3] | |
| -- | |
| -- >>> bubbleSort [2,3,1] | |
| -- [1,2,3] |
| 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 |
https://sk-design-labo.connpass.com/event/53851/
| module Monoid exposing (..) | |
| import Html exposing (text) | |
| main = text <| toString <| sum [1,2,3] | |
| type alias Monoid a = | |
| { empty : a | |
| , append : a -> a -> a | |
| } |