#多相な関数の定義から学ぶ、型クラスデザインパターン
twitter: @OE_uia github: taisukeoe
##多相な関数
- 複数の異なる型に対して適用可能な関数
- どの型に対して定義されているか、静的に決定できる(定義されてない型の値を渡すとコンパイルエラーになる)
#! /usr/bin/python | |
# -*- coding: utf-8 -*- | |
#(注意) このファイルは, Tab=4で見ると見易い. | |
###################################################################################################### | |
# @file RegressionAnalysis.py | |
# @brief Numpyを利用して重回帰分析を行う. | |
# @note | |
# ■重回帰分析について |
import scalaz._ | |
import Free.FreeC | |
class DDD[Entity, ID] { | |
// repositoryへの操作を代数的データ型で定義し、それをFreeとCoyonedaの力によりモナドにして使う | |
sealed abstract class RepositoryDSL[A] | |
// 見つからないかもしれないので結果はOption型 | |
final case class ResolveBy(id: ID) extends RepositoryDSL[Option[Entity]] |
レンズは余状態余モナドの余代数だった | |
=================================== | |
余余余〜!別名`関数的参照`とも呼ばれる[レンズ](https://hackage.haskell.org/package/lens)はJavaのGetter, Setterと同等と[言われる](https://twitter.com/plt_borat/status/228009057670291456)関数型プログラミングのデザインパターンの一つです。 | |
レンズは余状態余モナドの余代数だと[聞いて](https://twitter.com/hiratara/status/317602743219003392)そうなのかーと思ってたのですが、ふと自分で実装してみたくなったので **余状態余モナドの余代数** として実装してみることにしました。 | |
ちなみにこの文章は`literate Haskell`という形式で書かれているのでダウンロードしてghciでロードすればすぐにでも自分で試すことができます。 | |
まず最初におまじない | |
> {-# LANGUAGE RankNTypes #-} |
package jp.hoge.app.androidcookpatern.View; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.graphics.Path; |
#!/bin/sh | |
exec scala -savecompiled "$0" $@ | |
!# | |
// | |
// Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> | |
// Modified 2014 AI2 <http://www.allenai.org> | |
// | |
// This script will check that the commit is correctly formatted. It only checks files that are to be committed. | |
// To be run this file should be at `.git/hooks/pre-commit`. |
import javax.servlet._ | |
import skinny.micro._ | |
class Bootstrap extends LifeCycle { | |
override def init(ctx: ServletContext) { | |
example.App.mount(ctx) | |
} | |
} |
NOTICE: This is just a draft of Skinny framework introduction (written in Japanese for now). English version will be published soon.
https://github.com/seratch/skinny-framework
Skinny Framework は Scala のフルスタックな Web アプリケーション開発フレームワークです。2014/03 を目処に最初の安定バージョン 1.0.0 をリリースするべく精力的に開発しています。(追記: 2014/03/28 に 1.0.0 がリリースされました)