This file contains hidden or 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
package; | |
import cpp.Lib; | |
typedef A = { hoge:Int } | |
typedef B = { piyo:Int } | |
typedef C = { > A, > B, } | |
class Main { |
This file contains hidden or 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
{-# LANGUAGE ViewPatterns #-} | |
import Control.Applicative | |
import Data.List (find, genericIndex) | |
fixExpectation :: (Double, Integer) -> (Double, Integer) -> Integer -> Double | |
fixExpectation (sprob, sv) (fprob, fv) p = go 0 0 | |
where | |
patterns = let f m n = (fac <!!> m) `div` ( (fac <!!> n) * (fac <!!> (m-n)) ) in map (fromIntegral . f p) [0..p] | |
go m i | i <= p = let m' = m + fromIntegral (sv * i + fv * (p-i)) * sprob^i * fprob^(p-i) * (patterns <!!> i) in go m' (i+1) |
This file contains hidden or 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
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Conduit | |
import Data.Conduit.Network | |
main :: IO () | |
main = runTCPServer (serverSettings 3001 "127.0.0.1") echo | |
echo :: Application IO | |
echo app = appSource app $$ appSink app |
This file contains hidden or 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
QtQuickViewでQMLを表示する。 | |
C++のデータをQMLに渡す時は、QmlContext::setPropertyHogeHogeで渡す。 | |
C++で作成したQAbstractItemModelの派生クラスの各要素のデータは、そのままだとQMLからプロパティ名でアクセスできない。 | |
これをプロパティ名でアクセス可能にするため、QAbstractItemModel::roleNamesをオーバーライドしてプロパティ名の設定をする。 | |
QtQuick(QML/js)でViewの動作はかなりの部分が定義できるので、Haskellは低レイヤーの作業に専念出来る。 | |
C++関数やC++タイプのQMLへのエクスポート等は、テキストエディタのサンプル及び解説ページを参照。 |
This file contains hidden or 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
[ HaskellからDXライブラリを使う ] | |
1, まず本家からC#用パッケージをダウンロードしてくる。 | |
http://homepage2.nifty.com/natupaji/DxLib/dxdload.html | |
2, (1)でダウンロードしたzipから、DxLib.dllとDxDLL.hだけ抜き取ってくる。 | |
DxLib.dllは実行時に使う為。 | |
DxDLL.hはDLL内の関数の宣言内容を人間が把握する為。 | |
3, Haskellのソースコードを書く。DxDLL.hを参照しながら以下のコードを書く(test.hs)。 | |
コード例: |
This file contains hidden or 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
{--- 余再帰とその利用例 ---} | |
{- 末尾再帰と再帰と余再帰 | |
- | |
- 参考: http://d.hatena.ne.jp/kazu-yamamoto/20091122/1258899591 | |
- | |
- 末尾再帰 : 引数に結果を蓄積し、自身へgotoして処理の流れが戻ってこないようにする。正格なデータを処理する時に用いるとスタックやヒープの節約になる。 | |
- foldl f a [] = a | |
- foldl f a (x:xs) = foldl f (f a x) xs | |
- |
This file contains hidden or 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
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeFamilies, UndecidableInstances #-} | |
import Control.Applicative | |
import Control.Exception.Lifted | |
import Control.Monad | |
import Control.Monad.Base | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Control | |
import Control.Monad.Trans.Maybe | |
import qualified Data.Text as T |
This file contains hidden or 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
{-# LANGUAGE DeriveFunctor, FlexibleInstances, FlexibleContexts #-} | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Maybe | |
import Control.Monad.State | |
import qualified Control.Monad.Free as F | |
import qualified Data.Foldable as DF | |
import Prelude hiding (head,last) | |
{- |
This file contains hidden or 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 qualified Data.ByteString as BS | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import Data.Text.ICU.Convert | |
toUnicodeWithDetect :: FilePath -> IO T.Text | |
toUnicodeWithDetect fp = do | |
a <- BS.readFile fp | |
cons <- mapM (flip open Nothing) ns | |
let xs = take 1 $ filter (T.all (`notElem` errs)) $ map (flip toUnicode a) cons |
This file contains hidden or 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
{-# LANGUAGE OverloadedStrings, PatternGuards #-} | |
import qualified Codec.Binary.Url as CBU | |
import qualified Control.Concurrent as CC | |
import qualified Control.Concurrent.STM as STM | |
import qualified Control.Exception as CE | |
import qualified Control.Monad as CM | |
import qualified Control.Monad.Trans as CMT | |
import qualified Data.Aeson as A | |
import qualified Data.Attoparsec as DA |