first-class-instances: First class typeclass instances

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

See the README file in the project repository


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), Cabal (>=2.4.1.0 && <2.5), containers (>=0.6.0.1 && <0.7), template-haskell (>=2.14 && <2.15) [details]
License BSD-3-Clause
Copyright 2019 Matej Nižník
Author Matej Nižník
Maintainer matten@tuta.io
Category Language
Source repo head: git clone https://gitlab.com/thematten/first-class-instances
Uploaded by TheMatten at 2020-02-02T17:37:08Z
Distributions
Downloads 367 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-02-02 [all 1 reports]

Readme for first-class-instances-0.1.0.0

[back to package description]

first-class-instances

(Work in progress!)

Remember when you had some neat way of building instance out of another one, when some type had multiple interesting instances of the same class, or when it was possible to elegantly derive some instance for your type on paper, but compiler just wouldn't let you to use these things because of overlapping and stuff? Well, now you can!:

class Monad m => Teletype m where
  read  :: m String
  write :: String -> m ()

mkInst ''Teletype

hello :: Teletype m => m ()
hello = do
  write "What's your name?: "
  name <- read
  write $ "Hi " ++ name ++ "!\n"

main :: IO ()
main = Teletype inst getLine putStr ==> hello

first-class-instances allow you to treat typeclass instances as what they actually are - ordinary values. And Magic Insideā„¢ turns them back and forth between ordinary constraints when needed. Build instances from the others, locally from available functions or even dynamically at runtime! Or derive them using ordinary Haskell code and then promote into global ones using TH (TODO).

This library is still experimental, so please do not use it for serious things, but I welcome you to try it out and give some feedback!