相关疑难解决方法(0)

我滥用不安全的PerformIO吗?

为了熟悉unsafePerformIO(如何使用它以及何时使用它),我实现了一个用于生成唯一值的模块.

这就是我所拥有的:

module Unique (newUnique) where

import Data.IORef
import System.IO.Unsafe (unsafePerformIO)

-- Type to represent a unique thing.
-- Show is derived just for testing purposes.
newtype Unique = U Integer
  deriving Show

-- I believe this is the Haskell'98 derived instance, but
-- I want to be explicit, since its Eq instance is the most
-- important part of Unique.
instance Eq Unique where
  (U x) == (U y) = x == y

counter :: IORef Integer …
Run Code Online (Sandbox Code Playgroud)

haskell unsafe-perform-io

23
推荐指数
4
解决办法
6127
查看次数

如何从不纯的方法返回纯值

我知道它听起来一定是微不足道的,但我想知道如何从仿函数中展开一个值并将其作为纯值返回?

我试过了:

f::IO a->a
f x=(x>>=) 

f= >>=
Run Code Online (Sandbox Code Playgroud)

我应该在右侧放置什么?我不能使用,return因为它会再次包裹它.

monads haskell functor

2
推荐指数
1
解决办法
459
查看次数

标签 统计

haskell ×2

functor ×1

monads ×1

unsafe-perform-io ×1