# deriveAutoReg with superclass constraints

**URL:** <https://clash-lang.discourse.group/t/deriveautoreg-with-superclass-constraints/100>\
**Category:** Clash Help\
**Created:** [November 27, 2025, 6:21am UTC](https://clash-lang.discourse.group/t/deriveautoreg-with-superclass-constraints/100 "2025-11-27T06:21:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![elliotpotts](https://yyz2.discourse-cdn.com/free1/user_avatar/clash-lang.discourse.group/elliotpotts/32/45_2.png) [@elliotpotts](https://clash-lang.discourse.group/u/elliotpotts)\
**Post date:** [November 28, 2025, 2:18am UTC](https://clash-lang.discourse.group/t/deriveautoreg-with-superclass-constraints/100/3 "2025-11-28T02:18:59Z")

</div>

Ah, you’re right.  
I realise now that it’s the Vec in my original code (not present in my first example) causing issues:

```auto
data MsgConfig = MsgConfig
  { _msgChannelWidth :: Nat
  , _msgDataLen :: Nat
  }

type family MsgChannelWidth (cfg :: MsgConfig) :: Nat where
  MsgChannelWidth ('MsgConfig x _) = x

type family MsgDataLen (cfg :: MsgConfig) :: Nat where
  MsgDataLen ('MsgConfig _ x) = x

type KnownMsgConfig cfg = KnownNat (MsgChannelWidth cfg)

data Message (cfg :: MsgConfig) = Status
  { _msg_channel :: Unsigned (MsgChannelWidth cfg)
  , _msg_data :: Vec (MsgDataLen cfg) (Unsigned 8)
  , _msg_chksum :: Unsigned 4
  }
  deriving (Bundle, Generic, NFDataX)
deriving instance (KnownMsgConfig cfg) => BitPack (Message cfg)
makeLenses ''Message
deriveAutoReg ''Message

```

Doesn’t work because we need `KnownNat (MsgDataLen cfg)` to derive NFDataX for Vec.

---

_[View the full topic](https://clash-lang.discourse.group/t/deriveautoreg-with-superclass-constraints/100)._
