相关疑难解决方法(0)

可以纯粹执行`ST`之类的monad(没有'ST`库)吗?

这篇文章是有文化的Haskell.只需输入像"pad.lhs"这样的文件ghci就能运行它.

> {-# LANGUAGE GADTs, Rank2Types #-}
> import Control.Monad
> import Control.Monad.ST
> import Data.STRef
Run Code Online (Sandbox Code Playgroud)

好的,所以我能够想出如何ST用纯代码表示monad.首先,我们从我们的引用类型开始.它的具体价值并不重要.最重要的是PT s a不应该与任何其他类型同构forall s.(特别是,它既不应该同形()也不应该同形Void.)

> newtype PTRef s a = Ref {unref :: s a} -- This is defined liked this to make `toST'` work. It may be given a different definition.
Run Code Online (Sandbox Code Playgroud)

那种为s*->*,但现在不是真的很重要.对于我们所关心的一切,它可能是多面手的.

> data PT s a where
>     MkRef   :: a -> PT s …
Run Code Online (Sandbox Code Playgroud)

monads state haskell ghc purely-functional

32
推荐指数
3
解决办法
813
查看次数

标签 统计

ghc ×1

haskell ×1

monads ×1

purely-functional ×1

state ×1