我有以下代码,我不知道应该在??
. 还是多态模式不能完成?
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Tuple.Single.Class
( Single (..)
, pattern Single
) where
class Single t where
wrap :: a -> t a
unwrap :: t a -> a
pattern Single :: Single t => a -> t a
pattern Single a <- (unwrap -> a) where
Single a = wrap a
{-# COMPLETE Single :: ?? #-}
GHC 文件说,当所有的 conlikes 都是多态的时,你必须输入 conlike。
make 时??
()
,编译成功。但这是什么()
意思?GHC 表示仍然没有详尽的使用情况。
{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Data.Tuple.Single.Only
( Single (..)
, pattern Single
) where
import Data.Tuple.Only (Only (Only, fromOnly))
import Data.Tuple.Single.Class (Single (unwrap, wrap), pattern Single)
instance Single Only where
wrap = Only
unwrap = fromOnly
ghci> Single a = wrap 1 :: Only Int
<interactive>:2:1: warning: [-Wincomplete-uni-patterns]
Pattern match(es) are non-exhaustive
In a pattern binding: Patterns not matched: _
- GHC 8.6.5