Questions tagged «coerce»

1
通过`coerce`键入角色和令人困惑的行为
我有一个类型,Id a并且我正尝试防止意外强制,例如将an Id Double更改为an Id Int。 如果我正确理解类型角色,则不应编译以下内容。 {-# LANGUAGE RoleAnnotations #-} import Data.Coerce (coerce) type role Id nominal newtype Id a = Id String badKey :: Id Int badKey = coerce (Id "I point to a Double" :: Id Double) 不幸的是,它确实: Prelude> :load Id.hs [1 of 1] Compiling Main ( …
11 haskell  roles  coerce 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.