IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

2018-05-01から1ヶ月間の記事一覧

QuickCheckで固定長文字列を作る

*> sample' (vectorOf 4 $ choose ('a','z')) ["jvnv","ylqf","aoud","bdha","lekn","ahoy","yzdp","nyso","zzlo","gjii","cyjg"] Ascii文字列とかUnicode文字列とか生成する機能があります。一度しっかりドキュメントを読んでおくとお釣りか来る感じ。 *> s…

Windows10へのGitのインストール

インストールのログ Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\Users\User> iex (new-object net.webclient).downloadstring('https://get.scoop.sh') PowerShell requires an execution policy of 'RemoteSigne…

CPS

CPSによる階乗計算 > :{ | fac 0 k = k 1 | fac n k = fac (n-1) $ \res -> k $ (*) n res | :} > fac 3 id 6 > fac 3 (+1) -- (1 * 2 * 3) + 1 7 手計算してみる。 fac 3 k = fac 2 $ \res -> k $ (*) 3 res = fac 1 $ \res1 -> (\res -> k $ (*) 3 res) $ …

stackのghciをテスト側で開く

通常のghciで開くとlibまたはexe側でghciが開く $ stack ghci テスト側で開きたい時はテストスイート名を明示的に指定する。 $ stack ghci :RFC5646-test

stackでテストスイートを個別に実行する

name: hoge tests: foo-test: main: Spec.hs source-dirs: test bar-doctest: main: test/doctests.hs と2つのテストスイートfoo-testとbar-doctestを定義する。 このときstack testでテストが実行されるが、両方とも実行される。 片方だけ実行したい場合は …

Attopersecで正規表現{min,max}

Regrex {min, max} for Attoparsec

Applicative Mabyeで条件分岐

なんらかのデータを取得する処理をして、あればそれを使い、なければ、別途データを取得する というロジックは、よくあるのではないでしょうか。 例えば、このような場合です。 import qualified Data.HashMap.Lazy as HML m = HML.fromList [("k1", "**"), …

Contravariant

Data.Functor.Contravariant covariant functor ~~> produce something contravariant functor ~~> consume something (>$) = contramap . const const :: a -> b -> a contramap :: Contravariant f => (a -> b) -> f b -> f a contrampa . const = x -> y …

Lensの理解のために

haskell/lens.md at master · lotz84/haskell · GitHub haskell - How to write an instance of Control.Lens.AT - Stack Overflow Oleg's gists - Glassery

Isoの使い方

lambda > import Control.Lens lambda > :t iso iso :: (Functor f, Profunctor p) => (s1 -> a1) -> (b1 -> t1) -> p a2 (f b2) -> p s2 (f t2) lambda > let foo = iso (\((a,b),c)->(a,(b,c)) (\(a,(b,c))->((a,b),c))) lambda > let foo = iso (\((a,b),…

安全なhead

Preludeにあるheadは安全ではない lambda > import Control.Lens.Cons lambda > head [1,2,3] 1 lambda > head [] *** Exception: Prelude.head: empty list Safeパッケージがある。 lambda > import Safe lambda > headMay [1,2,3] Just 1 lambda > headMay…

Attopersecで無限ループをさせる簡単な方法

Infinite loop on Attopersec