diff --git a/src/Arithmetic/Fin.hs b/src/Arithmetic/Fin.hs index c43b4b3..447daeb 100644 --- a/src/Arithmetic/Fin.hs +++ b/src/Arithmetic/Fin.hs @@ -63,6 +63,7 @@ module Arithmetic.Fin , remWord# , fromInt , fromInt# + , constant# -- * Lift and Unlift , lift @@ -75,7 +76,7 @@ import Arithmetic.Nat (( Nat# n -> Fin# n remWord# w (Nat# n) = case n of 0# -> errorWithoutStackTrace "Arithmetic.Fin.remWord#: cannot divide by zero" _ -> Fin# (Exts.word2Int# (Exts.remWord# w (Exts.int2Word# n))) + +{- | Create an unlifted finite number from an unlifted natural number. +The upper bound is the first type argument so that user can use +type applications to clarify when it is helpful. For example: + +>>> Fin.constant# @10 N4# +-} +constant# :: forall (b :: GHC.Nat) (a :: GHC.Nat). (CmpNat a b ~ 'LT) => Nat# a -> Fin# b +constant# (Nat# i) = Fin# i