![](/img/trans.png)
[英]How to fold on list of WriterT in cats
我希望在不運行它們的情況下將 Writer Monad 列表從貓折疊到一位大作家。 例如:import cats.data.Writer import cats.instances.vector._ import cats.instances.list._ import cats.instances ...
[英]How to fold on list of WriterT in cats
我希望在不運行它們的情況下將 Writer Monad 列表從貓折疊到一位大作家。 例如:import cats.data.Writer import cats.instances.vector._ import cats.instances.list._ import cats.instances ...
[英]LYAH - Understanding comment about “tell” when chaining Writer monads
問題在底部以粗體顯示。 LYAH 給出了在Writer monad 中使用do表示法的示例import Control.Monad.Writer logNumber :: Int -> Writer [String] Int logNumber x = writer (x, ["numbe ...
[英]How define instance Monad Writer with custom data type
我有模塊: 我試圖編寫batchLog函數,但編譯器說: 所以,為什么我需要定義任何其他的 Monad。 我已經有instance (Monoid w) => Monad (Writer w)和instance (Semigroup a, Num a) => Monoid (Fo ...
[英]Cats Writer type-mismatch in for expression
我創建了一個類型 type ResultLog = Writer[List[String], Option[Double]] 我的名為process函數希望在Input列表上工作並返回ResultLog : Input是一個案例類: 我得到的是這些編譯器錯誤: ...
[英]Question about the Writer monad as taught in LYAH. (How did the appending to the log take place?)
我正在從“Learn you a Haskell for Great Good”教程中學習 Haskell,並且我已經學習了關於writer monads的部分。 這是我無法弄清楚的示例。 我試圖了解do塊返回的Writer wa monad 中的幺半群值w是如何改變的。 本教程沒有詳細介紹ma ...
[英]Stacking monads Writer and OptionT
我有以下代碼: 我想在處理的每個階段添加日志記錄-因此,我需要介紹writer monad並將其與monad轉換器OptionT堆疊在一起。 你能建議如何做到嗎? ...
[英]Writer monad and unsequence
我正在使用Writer monad跟蹤任意值(例如Int )上的錯誤(“沖突”)標志。 一旦設置了標志,它就是“粘滯的”,並將其自身附加到由於任何帶有標記的操作而產生的所有值。 有時碰撞標志與各個值相關聯,有時我想與諸如列表之類的復合結構相關聯。 當然,一旦為整個列表設置了碰撞標志,就 ...
[英]Writer Monad Nested Twice
我試圖使用Monad變形金剛兩次嵌套作家monad。 這是一個草圖: foo函數無法編譯,因為我需要在Struct monad上使用tell ,而不是Collision 。 有可能嗎? ...
[英]Function composition with the Writer monad?
我正在研究Writer monad,並具有以下內容: 錯誤: 為什么使用會出現此計算錯誤. 而不是$ ? 也許我對功能組成的理解不正確? ...
[英]How do I access both the value and accumulator of a Writer monad within a 'do' block (PureScript)?
我現在正在學習Writer monad,但不確定在do塊中同時讀取monad的值和累加器是否正確。 例如,在下面的coltzSeq函數中,我想讀取Array累加器的長度作為該函數的最終計算。 是否有可能這樣做或不正確使用Writer? 顯然,我可以讓調用者讀取最終數組的長度,或者可以使用S ...
[英]Wrapping Maybe in WriterT to add logging
我完全陷入困境,我覺得我現在可以使用一些幫助,只是為了保持理智。 我想要一些簡單的東西,比如為返回Maybe的函數添加日志記錄功能,但無論我怎么努力,我都無法獲得正確的類型。 這是(我認為)我能得到的最接近的: 這仍然導致我輸入錯誤: 我應該如何調整代碼以使其編譯和工作? ...
[英]Haskell Write Monad for expressions
我正在嘗試設計嵌入式語言,其中操作可以根據值引發某些標志。 我預見到對標量值和向量(例如,地圖,折疊等)的操作。我的想法是使用Writer Monad來跟蹤標志。 簡化示例,其中實際類型為“ Int”,並且如果參數中的任何一個為0,則引發標志。 我幾乎不確定什么是實現此目標的最佳方法 ...
[英]Validating XML with Writer and Kleisli in Scala
這是我先前問題的跟進 假設我需要驗證這樣的XML: 我需要確保根元素具有標簽a並且也依次具有子元素<a1>xxx</a1> , <a2>yyy</a2>和<a3>zzz</a3> 。 我想使用List[S ...
[英]scalaz - function composition - WriterT
讓我們在\\/上定義一個Kleisli : 以及一個用於測試目的的特殊功能: 功能組合工作順利: 我想添加日志記錄: 這似乎有所期望的行為: 光滑。 但是,我正在努力組建一個運營商: 結合WriterT應用>>>的值 ...
[英]Understanding example on Writer Monad
我正在《 Learn a A Haskell》一書中學習作家Monad。 這是一段代碼: 運行multWithLog ,結果如下: 在這行上: 很容易看到a = 3和b = 5 ,因為它們都在return函數上相乘。 我不明白的是為什么這些值是3和5 。 a ...
[英]How to compose functions that return Writer[List[Int], Int]?
假設我有一些函數Int => Int由andThen組成: 現在我還需要返回中間結果。 所以我可以將所有這些函數轉換為Int => (List[Int], Int) ,其中列表包含參數。 我可以使用scalaz Writer[List[Int], Int]來表示對(L ...
[英]context bound of scalar.Coyoneda.liftTF
看完RúnarBjarnason發人深省的視頻“價格合理的Monad的可組合應用程序體系結構”后,我開始在Scalaz中編寫視頻中提供的示例。 當為Interact App實現基於作者的解釋器時,我有些驚訝。 這是代碼, 當我嘗試將ConsoleW提升為用於交互免費Monad的解釋器 ...
[英]Is the Writer Monad effectively the same as the State Monad?
有一個偉大的教程在這里 ,這似乎暗示,我認為作家單子基本上是做代表的工作的特殊情況,元組對象(A,B)。 作者在左邊積累了值(即A),並且A與它有相應的Monoid(因此它可以累積或改變狀態)。 如果A是一個集合,那么它就會累積。 State Monad也是一個處理內部元組的對象。 ...
[英]Memoization in the Writer monad
注意我只是想了解下面這段特定代碼中發生的事情。 我知道這可能不是解決問題的最佳方法。 我試圖將懶惰的Writer monad與已記憶的fibonacci函數一起使用,以計算該函數被調用的次數。 該函數快速返回正確的值,但Writer環境從不返回且不使用任何CPU或內存。 有人可 ...
[英]Where is the official definition of 'bind' and 'return' for the Writer Monad in Haskell?
到目前為止,我發現: 給出>>=定義並return 官方代碼在哪里? ...