proxied: Make functions consume Proxy instead of undefined

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

proxied is a simple library that exports a function to convert constant functions to ones that take a proxy value in the Data.Proxied module. This is useful for retrofiting typeclasses that have functions that return a constant value for any value of a particular type (but still need to consume some value, since one of the parameterized types must appear in a typeclass function). Often, these functions are given undefined as an argument, which might be considered poor design.

Proxy, however, does not carry any of the error-throwing risks of undefined, so it is much more preferable to take Proxy as an argument to a constant function instead of undefined. Unfortunately, Proxy wasn't included in base until GHC 7.8, so many of base's typeclasses still contain constant functions that aren't amenable to passing Proxy. proxied addresses this issue by providing variants of those typeclass functions that take an explicit proxy value.

This library also contains the Data.Proxyless module, which works in the opposite direction. That is, one can take functions which take Proxy (or undefined) as an argument and convert them to functions which take no arguments. This trick relies on the -XTypeApplications extension, so it is only available with GHC 8.0 or later. This library also offers Data.Proxyless.RequiredTypeArguments, a variant of Data.Proxyless that uses -XRequiredTypeArguments to make type arguments explicit, which is only available with GHC 9.10 or later.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1, 0.2, 0.3, 0.3.1, 0.3.2
Change log CHANGELOG.md
Dependencies base (>=4.3 && <5), generic-deriving (>=1.10.1 && <2), tagged (>=0.4.4 && <1) [details]
Tested with ghc ==7.0.4, ghc ==7.2.2, ghc ==7.4.2, ghc ==7.6.3, ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.5, ghc ==9.8.2, ghc ==9.10.1
License BSD-3-Clause
Copyright (C) 2016-2017 Ryan Scott
Author Ryan Scott
Maintainer Ryan Scott <ryan.gl.scott@gmail.com>
Category Data
Home page https://github.com/RyanGlScott/proxied
Bug tracker https://github.com/RyanGlScott/proxied/issues
Source repo head: git clone https://github.com/RyanGlScott/proxied
Uploaded by ryanglscott at 2024-04-20T11:56:13Z
Distributions LTSHaskell:0.3.2, NixOS:0.3.2, Stackage:0.3.2
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 4091 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-04-20 [all 1 reports]

Readme for proxied-0.3.2

[back to package description]

proxied

Hackage Hackage Dependencies Haskell Programming Language BSD3 License Build Status

proxied is a simple library that exports a function to convert constant functions to ones that take a proxy value in the Data.Proxied. This is useful for retrofiting typeclasses that have functions that return a constant value for any value of a particular type (but still need to consume some value, since one of the parameterized types must appear in a typeclass function). Often, these functions are given undefined as an argument, which might be considered poor design.

Proxy, however, does not carry any of the error-throwing risks of undefined, so it is much more preferable to take Proxy as an argument to a constant function instead of undefined. Unfortunately, Proxy wasn't included in base until GHC 7.8, so many of base's typeclasses still contain constant functions that aren't amenable to passing Proxy. proxied addresses this issue by providing variants of those typeclass functions that take an explicit proxy value.

This library also contains the Data.Proxyless module, which works in the opposite direction. That is, one can take functions which take Proxy (or undefined) as an argument and convert them to functions which take no arguments. This trick relies on the -XTypeApplications extension, so it is only available with GHC 8.0 or later. This library also offers Data.Proxyless.RequiredTypeArguments, a variant of Data.Proxyless that uses -XRequiredTypeArguments to make type arguments explicit, which is only available with GHC 9.10 or later.