我現在正在學習Writer monad,並且我不確定想要在do塊中讀取monad的值和累加器是否正確。例如,在下面的coltzSeq函數中,我想讀取數組累加器的長度作爲函數的最終計算。是否有可能做到這一點或這是一個不正確的使用Writer?顯然,我可以讓調用者閱讀最終數組的長度,或者我可以使用State monad,但這僅僅是對我的練習。 module Main where
import Pr
在PureScript鹵素項目中,我想將狀態設置爲隨機數,但是如何提取該值?正常的 r <- randomInt 1 10
當它在eval函數內部時不會編譯。 module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Random (randomInt, RANDOM
是否有方法來定義表示行多態記錄的類型/別名? 因此,考慮這個例子 tester :: forall r. {val :: Int | r} -> Int
tester a =
a.val
callTester = tester {val: 1, b: 2}
我要定義的記錄類型作爲別名。類似於 type Val = forall r. {val :: Int | r}
tes
我在psci repl中執行此操作。這是我的函數: $> import Data.List
$> let f (x:xs) = x
$> let f Nil = Nil
$> let a = 1:2:3:Nil
$> f a
我得到這個錯誤: Could not match type
Int
with type
List t0
while