with-location-0.1.0/0000755000000000000000000000000012672202265012463 5ustar0000000000000000with-location-0.1.0/LICENSE0000644000000000000000000000206212672202265013470 0ustar0000000000000000Copyright (c) 2016 Simon Hengel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. with-location-0.1.0/with-location.cabal0000644000000000000000000000215412672202265016232 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.11.0. -- -- see: https://github.com/sol/hpack name: with-location version: 0.1.0 synopsis: Use ImplicitParams-based source locations in a backward compatible way category: Data homepage: https://github.com/sol/with-location#readme bug-reports: https://github.com/sol/with-location/issues maintainer: Simon Hengel license: MIT license-file: LICENSE cabal-version: >= 1.10 build-type: Simple source-repository head type: git location: https://github.com/sol/with-location library hs-source-dirs: src ghc-options: -Wall build-depends: base == 4.* exposed-modules: Data.WithLocation default-language: Haskell2010 test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs hs-source-dirs: test ghc-options: -Wall build-depends: base == 4.* , hspec , with-location other-modules: Data.WithLocationSpec default-language: Haskell2010 with-location-0.1.0/Setup.lhs0000644000000000000000000000011412672202265014267 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain with-location-0.1.0/test/0000755000000000000000000000000012672202265013442 5ustar0000000000000000with-location-0.1.0/test/Spec.hs0000644000000000000000000000005412672202265014667 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} with-location-0.1.0/test/Data/0000755000000000000000000000000012672202265014313 5ustar0000000000000000with-location-0.1.0/test/Data/WithLocationSpec.hs0000644000000000000000000000060312672202265020065 0ustar0000000000000000{-# LANGUAGE CPP #-} module Data.WithLocationSpec (spec) where import Test.Hspec import Data.WithLocation spec :: Spec spec = do describe "location" $ do it "returns a source location" $ do #if MIN_VERSION_base(4,8,1) location `shouldBe` Just (Location "main" "Data.WithLocationSpec" __FILE__ __LINE__ 7) #else location `shouldBe` Nothing #endif with-location-0.1.0/src/0000755000000000000000000000000012672202265013252 5ustar0000000000000000with-location-0.1.0/src/Data/0000755000000000000000000000000012672202265014123 5ustar0000000000000000with-location-0.1.0/src/Data/WithLocation.hs0000644000000000000000000000160612672202265017066 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-} #if MIN_VERSION_base(4,8,1) #define HAS_SOURCE_LOCATIONS {-# LANGUAGE ImplicitParams #-} #endif module Data.WithLocation where #ifdef HAS_SOURCE_LOCATIONS #if !(MIN_VERSION_base(4,9,0)) import GHC.SrcLoc #endif import GHC.Stack #endif #ifdef HAS_SOURCE_LOCATIONS type WithLocation a = (?loc :: CallStack) => a #else type WithLocation a = a #endif data Location = Location { locationPackage :: String , locationModule :: String , locationFile :: FilePath , locationLine :: Int , locationColumn :: Int } deriving (Eq, Ord, Show) location :: WithLocation (Maybe Location) #ifdef HAS_SOURCE_LOCATIONS location = case reverse (getCallStack ?loc) of (_, loc) : _ -> Just $ Location (srcLocPackage loc) (srcLocModule loc) (srcLocFile loc) (srcLocStartLine loc) (srcLocStartCol loc) [] -> Nothing #else location = Nothing #endif