vscodeでのhaskell開発環境作成

概要 macにて、vscodeでhaskell開発環境を作成したので手順を記載 ほぼVS Code と haskell-ide-engine で Haskell 開発環境を構築するのままだけど一部動かなかったところがあるのでメモ。 手順 stack brew install stack echo "export PATH=$PATH:~/.local/…

cloud functions

ライブラリインストール npm install -g firebase-tools プロジェクト作成 firebase init cloud functionsを選択 プロジェクトデプロイ firebase deploy helloWorldエンドポイントへのアクセスURLが表示されるので、アクセスすると結果が帰ってくる あとはお…

vueで遊ぶ 第2回 〜vue-router

インストール yarn add vue-router main.jsを書き換える import Vue from 'vue' import VueRouter from 'vue-router' import FoodList from './components/FoodList/FoodList' import EditFood from './components/EditFood/EditFood' import App from './Ap…

firebaseでサーバレス 第4回 〜firestoreへのinsert

html <label>名前</label><input v-model="name"/><br/> <label>タンパク質</label><input v-model="protein"/><br/> <label>脂質</label><input v-model="lipid"/><br/> <label>炭水化物</label><input v-model="carbo"/><br/> <button v-stream:click="plus$">登録</button> typescript const db = firebase.firestore() const foodsPms …</br/></br/></br/></br/>

firebaseでサーバレス 第3回 〜Webからのfirestore検索とリスト表示

vue-rxとrxjsのインストール yarn add vue-rx rxjs htmlの編集 <table> <thead> <tr> <th>名前</th> <th>タンパク質</th> <th>脂質</th> <th>炭水化物</th> </tr> </thead> <tbody> <tr v-for="(row, index) in foods" :key="index"> <td>{{ row["名前"] }}</td> <td>{{ row["タンパク質"] }}</td> <td>{{ row["脂質"] }}</td> <td>{{ row["炭水化物"] }}</td> </tr></tbody></table>

firebaseでサーバレス 第2回 〜Webからのfirestore検索

frontendプロジェクト配下で下記のコマンドを実行しfirebaseをインストール yarn add firebase とりあえずfirestoreのfoods配下のアクセス権限を与える service cloud.firestore { match /databases/{database}/documents { match /foods/{food} { allow rea…

firebaseでサーバレス 第1回 〜プロジェクト作成

vueでフロントエンドを軽く作りたいため、 サーバーサイドはfirebaseにすべておまかせしようと思う firebaseのプロジェクト作成 トップページ https://firebase.google.com/?hl=ja プロジェクトの追加 ウェブアプリにFirebaseを追加、でスクリプトタグを取得…

vueで遊ぶ 第1回 〜プロジェクト作成

SPAをやりたくて今流行のvueで始めてみました。 vue cliのインストール yarn global add @vue/cli projectの作成 vue create ngiy-frontend manualを選択 Typescriptを選択 In package.jsonを選択 Use Yarnを選択 projectの起動 cd ngiy-frontend yarn serve…

モナドトランスフォーマー (1)

ListとList[Option]とOptionの共存 val intList: List[Int] = List(1, 2, 3, 5) val strOptList: List[Option[String]] = List(Some("a"), Some("c"), None, Some("d")) val option: Option[Int] = Option(1) val t: OptionT[List, (Int, String, Int)] = fo…

プログラミングhaskell 9章 version scala 〜後半(ライフゲーム)〜

type Board = List[Pos] val width: Int = 5 val height: Int = 5 def showcells(b: Board): IO[Unit] = seqn(b.map(p => writeat(p)("○"))) def isAlive(b: Board)(p: Pos): Boolean = b.contains(p) def isEmpty(b: Board)(p: Pos): Boolean = !isAlive(b)…

Stateモナドの使い道 [フィボナッチ]

case class S(current: Int, next: Int) { def process() = S(next, current + next) } val fib: Stream[State[S, Int]] = Stream.continually(State(s => (s.process(), s.current))) val state: State[S, Stream[Int]] = fib.take(15).sequence println(st…

プログラミングhaskell 9章 version scala 〜後半〜

val box: List[String] = List( "+---------------+", "| |", "+---+---+---+---+", "| q | c | d | = |", "+---+---+---+---+", "| 1 | 2 | 3 | + |", "+---+---+---+---+", "| 4 | 5 | 6 | - |", "+---+---+---+---+", "| 7 | 8 | 9 | * |", "+---+---+---…

プログラミングhaskell 9章 version scala 〜前半〜

def getChar: IO[Char] = IO(System.in.read().toChar) def putChar(c: Char): IO[Unit] = IO(print(c)) def echo: IO[Unit] = for { c <- getChar _ <- putChar('\n') _ <- putChar(c) _ <- putChar('\n') } yield () def getLine: IO[List[Char]] = for { …

Writerモナドの使い道 [自作モノイド]

case class Product(money: Int) case class Coins(gohyakuen: Int, hyakuen: Int, gojuen: Int, juen: Int) { def +(other: Coins) = Coins(gohyakuen + other.gohyakuen, hyakuen + other.hyakuen, gojuen + other.gojuen, juen + other.juen) def sum(): …

Writerモナドの使い道 [実行回数]

def hoge(): Writer[Int, String] = for { _ <- Writer.tell(1) r <- Writer.value[Int, String]("hoge") } yield r val w: Writer[Int, List[String]] = List.range(0, 100).map(_ => hoge()).sequence println(w.run) // (hoge()実行回数, 結果のリスト)

Writerモナドの使い道 [ログ出力]

def selectIdFromDb(): Writer[List[String], Int] = for { _ <- Writer.tell(List("db access start.")) _ <- Writer.tell(List("TODO: db access 実装")) r <- Writer.value[List[String], Int](1) _ <- Writer.tell(List("db access end.")) } yield r de…

プログラミングhaskell 8章 version scala 〜後半〜

前半はこちら def token[T](p: Parser[T]): Parser[T] = for { _ <- space v <- p _ <- space } yield v def identifier: Parser[String] = token(ident) def natural: Parser[Int] = token(nat) def symbol(s: String): Parser[String] = token(string(s)) …

プログラミングhaskell 8章 version scala 〜前半〜

type Parser[T] = StateT[Option, String, T] def pure[T](x: T): Parser[T] = StateT.pure[Option, String, T](x) def failure: Parser[String] = StateT[Option, String, String](_ => None) def item: Parser[String] = StateT{ case "" => None case xs …

Validated(Applicative)のsequence

ListのEitherのsequenceは最初のエラーだけしかかえってこない。 ListのValidatedのsequenceはすべてのエラーがかえってくる。 val eithers: List[Either[String, Int]] = List(Right(1), Left("error1"), Right(2), Left("error2"), Right(3)) val validate…

Readerモナドの使い道 [DI]

catsを使用したReaderモナドの使い道例として、DIのサンプル trait DbAccessor { def select: List[String] def count: Int } object DbAccessorImpl extends DbAccessor { override def select: List[String] = { // TODO: dbAccess処理 List.empty } overr…