1{-# LANGUAGE ConstraintKinds #-} 2{-# LANGUAGE KindSignatures #-} 3{-# LANGUAGE CPP #-} 4{-# LANGUAGE ImplicitParams #-} 5 6-- | ConstraintKind synonym for marking partial functions 7module Safe.Partial(Partial) where 8 9-- Let things work through ghci alone 10#ifndef MIN_VERSION_base 11#define MIN_VERSION_base(x,y,z) 1 12#endif 13 14-- GHC has changed its opinion on the location a few times 15-- v0: GHC 7.4.1, has ConstraintKinds 16-- v1: GHC 7.10.2, base 4.8.1.0 = CallStack 17-- v2: GHC 8.0.1, base 4.9.0.0 = HasCallStack 18 19#if __GLASGOW_HASKELL__ >= 800 20#define OPTION 2 21#elif __GLASGOW_HASKELL__ >= 710 && MIN_VERSION_base(4,8,1) 22#define OPTION 1 23#else 24#define OPTION 0 25#endif 26 27 28#if OPTION == 0 29import GHC.Exts 30#else 31import GHC.Stack 32#endif 33 34-- | A constraint synonym which denotes that the function is partial, and will 35-- (on GHC 8.* and up) produce a stack trace on failure. 36-- You may mark your own non-total functions as Partial, if necessary, and this 37-- will ensure that they produce useful stack traces. 38#if OPTION == 0 39type Partial = (() :: Constraint) 40#elif OPTION == 1 41type Partial = (?loc :: CallStack) 42#else 43type Partial = HasCallStack 44#endif 45