[過去ログ] 関数型プログラミング言語Haskell Part33 (1002レス)
上下前次1-新
抽出解除 レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
95: 2020/03/27(金)20:21:43.46 ID:inQsOLrL(5/5) AAS
>>93
自分も>>74の理解で問題ないと思うんだよ
237: 2020/04/19(日)01:35:32.46 ID:WM8Q0HWB(1/2) AAS
[状態モナド](外部リンク:wiki.haskell.orgを
[随伴](外部リンク:en.wikipedia.org on Rails
に乗せてみる。
``` code
type W x a b = (a, x) -> (b, x)
type S x a b = a -> x -> (b, x)
in_away :: W x c d -> W x b c -> W x a b -> W x a d
in_away cd bc ab = cd . bc . ab
in_home :: S x c d -> S x b c -> S x a b -> S x a d
-- in_home cd bc ab = to_home $ in_away (to_away cd) (to_away bc) (to_away ab) where
-- in_home cd bc ab = ext cd . ext bc . ab where
in_home cd bc ab a = new a %>>=% ab %>>=% bc %>>=% cd where
(%>>=%) = flip ext
ext = to_home_fmap . to_away
new = to_home id
to_home_fmap = (.)
to_home = curry
to_away = uncurry
```
`to_home`が[記事](外部リンク:en.wikipedia.orgでの`Phi`
に、`ext`が[Kleisliのスター](外部リンク:en.wikipedia.org
に対応する。`in_away`は通常の関数の合成で、`in_home`はそれを黒魔術に
翻訳している。
[継続モナド](外部リンク:wiki.haskell.orgも随伴で書ける。
310: 2020/05/04(月)16:45:39.46 ID:R0S0SfqY(1) AAS
ocamlはせっかく盛り返してたのに失言でだいなし
323(1): 2020/05/23(土)00:35:45.46 ID:PUmkxvlF(1/3) AAS
次のように、一つのモナドを遅延的に無限に評価できる関数 repM は定義できるでしょうか?
repM :: (Monad) => m a -> m [a]
xs <- repM (return 1)
print $ take 3 xs -- [1, 1, 1]
ys <- take 2 <$> repM (return 1)
print ys -- [1, 1]
556(1): 2020/11/03(火)11:32:34.46 ID:WdkpFDBO(2/2) AAS
一応、Num (f a)は導出できるけど、それで定義した(+)だと
交換則(x + y = y + x)が成り立つ保証がないからじゃないかねぇ
(パーサの順番を入れ替えた場合を考えるとわかりやすい)
{-# LANGUAGE FlexibleInstances #-}
instance (Num a, Applicative f) => Num (f a) where
x + y = (+) <$> x <*> y
x * y = (*) <$> x <*> y
abs x = abs <$> x
signum x = signum <$> x
negate x = negate <$> x
fromInteger n = pure $ fromInteger n
673: 2021/01/21(木)21:44:08.46 ID:AWFMWVQb(1) AAS
・Haskellが欲しかったポジションはなんかPythonにとられてしまった
679(1): 2021/01/23(土)13:17:02.46 ID:u7XOzuV6(1/2) AAS
>>665
ListT を使えばと思ったけどだめだった。
・参考
外部リンク:blog.mudatobunka.org
・残骸
module Rand2 where
-- stack install list-t
-- stack exec ghci
import Control.Monad.IO.Class ( liftIO )
import ListT ( ListT, toList )
import System.Random ( Random(randomIO, randomRIO) )
t1 :: ListT IO Int
t1 = return 3
t2 :: ListT IO Int
t2 = liftIO (randomIO :: IO Int)
t3 :: ListT IO [Int]
t3 = repeat <$> t2
output :: ListT IO [Int] -> IO ()
output t3 = do
li0 <- toList t3
print $ take 10 $ head li0
692: 2021/01/25(月)13:33:07.46 ID:/TZZteD8(2/2) AAS
安価ミス>>688
750: 2021/02/18(木)09:31:00.46 ID:8Wc99cSo(2/2) AAS
あ、イヤ違う
勘違いでした
すいません
911(1): 2021/09/27(月)18:11:25.46 ID:XYchXu+H(1) AAS
>>910
mutable stateの排他制御をしてないから複数のスレッドで実行するとまずいことが起こるかもしれない、ってことじゃないの?
排他制御
外部リンク:ja.wikipedia.org
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.045s