我正在将 History.js 中的绑定编写到 PureScript 中,但仍在努力理解 Eff monad、一排效果是什么以及它们为何有价值。现在我写了以下内容EasyFFI
type Title = String
type Url = String
type State = forall a. {title :: Title, url :: Url | a}
type Data = forall a. { | a}
type StateUpdater = Data -> Title -> Url -> Unit
-- this function is a work around for 'data' as a reserved word.
foreign import getData
"function getData(state){ return state['data']; }"
:: forall a b. { | a} -> b
unwrapState :: StateUpdater -> State -> Unit
unwrapState f s = f (getData s) s.title s.url
replaceState' :: StateUpdater
replaceState' = unsafeForeignProcedure ["data","title","url"] "History.replaceState(data,title,url)"
replaceState :: State -> Unit
replaceState = unwrapState replaceState'
foreign import data BeforeEach :: !
beforeEach :: forall e a. Eff e a -> Eff (beforeEach :: BeforeEach | e) Unit
beforeEach = unsafeForeignProcedure ["fn",""] "window.beforeEach(fn);"
稍后在代码中我有以下内容:
beforeEach $ do
replaceState {title = "wowzers!", url = "/foos"}
并得到以下错误
Cannot unify Prelude.Unit with Control.Monad.Eff.Eff u2518 u2517.
我尝试以各种方式操纵类型签名以尝试使其全部对齐,但我真的不明白出了什么问题。所以它只是在这一点上猜测。