In Idris, you cannot map a pattern to a type, and suppose you can, no one is allowed to list all possible types, so it cannot be complete.
The only thing you need is proof that type a is inside some specific set, and we call this sentence as ByteWidthAvailable .
data ByteWidthAvailable : Type -> Type where IntBWA : ByteWidthAvailable Int ChaBWA : ByteWidthAvailable Char total byteWidth : (a : Type) -> {auto prf: ByteWidthAvailable a} -> Int byteWidth _ {prf = IntBWA} = 8 byteWidth _ {prf = ChaBWA} = 1
The only trick here is the auto command provided by Idris, which helps to automatically generate evidence on the call site, so you can call byteWidth as byteWidth Char instead of byteWidth Char {prf = ChaBWA} .
luochen1990
source share