相关疑难解决方法(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
查看次数

标签 统计

haskell ×1

unsafe-perform-io ×1