Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Created January 22, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithrandi/d3d02aedab4b8cf900c2a566a90a06d1 to your computer and use it in GitHub Desktop.
Save mithrandi/d3d02aedab4b8cf900c2a566a90a06d1 to your computer and use it in GitHub Desktop.
genDefunSymbols [''Leverage]
promoteOnly
[d|
validLeverageAmt :: Nat -> Symbol -> Symbol -> ()
validLeverageAmt l b q =
if l `elem` leverage b q
then ()
else
typeError
( ShowType l
:<>: Text " is not an available leverage multiplier for pair "
:<>: Text b
:<>: Text "/"
:<>: Text q
)
|]
type ValidLeverage l b q =
( KnownNat l,
MarginPair b q,
ValidLeverageAmt l b q ~ '()
)
type family ValidLeverageAmt l b q s :: Constraint where
ValidLeverageAmt l b q '[] =
TypeError
( 'ShowType l
':<>: 'Text " is not an available leverage multiplier for pair "
':<>: 'Text b
':<>: 'Text "/"
':<>: 'Text q
)
ValidLeverageAmt l b q (l ': s) = ()
type ValidLeverage l b q =
( KnownNat l,
MarginPair b q,
ValidLeverageAmt l b q (Leverage b q)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment