我希望通过Bool
为Finite 2
定义新类的实例,而不创建部分功能,但它不起作用。
我的代码:
-- SO test case, re: my HasFin instance for Bool.
--
-- David Banas <capn.freako@gmail.com>
-- February 9, 2018
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
module Bogus.BoolHasFin where
import GHC.TypeLits
import Data.Finite
import Data.Finite.Internal (Finite(..))
class KnownNat (Card a) => HasFin a where
type Card a :: Nat
toFin :: a -> Finite (Card a)
unFin :: Finite (Card a) -> a
instance HasFin Bool where
type Card Bool = 2
toFin False = finite 0
toFin True = finite 1
unFin = \case
Finite 0 -> False
Finite 1 -> True
GHC编制结果:
Davids-Air-2:test dbanas$ stack ghc -- -c so_BoolHasFin.hs
so_BoolHasFin.hs:30:11: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative:
Patterns not matched: (Finite p) where p is not one of {1, 0}
任何人都可以帮助我理解为什么我会收到这个警告吗?
似乎,通过unFin
将Finite 2
的论证限制在一起,应该已经足够了。
于2018-02-10添加:
根据Conal私下提出的建议,此代码:
unFin (Finite 0) = False
unFin _ = True
消除了警告。
答案 0 :(得分:6)
我认为至少在某种程度上是因为protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
var db = new dbContext();
var CustItem = db.customer.ToList();
customerDropDownList.DataSource = CustItem;
customerDropDownList.DataTextField = "cust";
customerDropDownList.DataValueField = "cust";
customerDropDownList.DataBind();
}
}
的定义中没有任何内容限制所包含的Finite
在假定范围内({{1} } Integer
}:0
。