對不起,如果這個問題似乎有點微不足道......它不適合我。 我愉快地由下列單子: type SB i a = ReaderT (AlgRO i) (State (AlgState i)) a
其是,阱,表現良好的單子。 ReaderT是一個monad變換器,State是狀態monad,AlgRO和AlgState是分別在i中爲mutable和read-only狀態分別參數化的數據類型。現在,
我試圖用Haskell將簡單(但非常大)的樹結構保存到二進制文件中。結構看起來是這樣的:
-- For simplicity assume each Node has only 4 childs
data Tree = Node [Tree] | Leaf [Int]
這裏是我所需要的數據看磁盤上: 每個節點有4個32位偏移到它的孩子,然後按照孩子的開始。 我不太在乎葉子,假設它只有n個
我想與哈斯克爾Ubigraph,但我相信我的問題是更通用的。我試圖編譯: import Graphics.Ubigraph
import Control.Monad
import System.Posix.Unistd
main = do
h <- initHubigraph "http://127.0.0.1:20738/RPC2"
runHubigraph op h
我試圖修改Data.Binary.PutM monad成monad變換器。於是我開始了變化它的定義從 newtype PutM a = Put { unPut :: PairS a } 到 newtype PutM a = Put { unPut :: Identity (PairS a) } 那麼當然我改變了回報和>> =函數的實現: 來源: return a = Put $ PairS a m
我正在閱讀紙張Typed Logical Variables in Haskell,但我無法理解最終實現的細節。特別是,回溯狀態變壓器第4節介紹了由於某些原因,不認得我,GHC認爲我需要一個(ST a)例如MonadPlus在功能unify,如下: newtype BackT m a = BT { run :: forall b . (a -> m [b]) -> m [b] }
instan
我有一個類型 type T s r a = StateT [s] (ListT (Reader r)) a
我想創建產生每個當前狀態的一元價值 states :: T a r a
但我今天感覺很蠢,而且我不知道如何將T a r [a]的值轉換爲T a r a。 states = do
as <- get
-- insert magic
return a
問題是這樣的。我有: f :: MonadIO m => ReaderT FooBar m Answer;
f = (liftIO getArgs) >>= ...
我需要運行修改參數。然而,由於m是未知的,我不能簡單地用 mapReaderT (withArgs args) :: ReaderT r IO b -> ReaderT r IO b
,因爲我需要以某種方式改變(withAr