first-class-instances: First class typeclass instances

[ bsd3, language, library ] [ Propose Tags ]

See the README file in the project repository

[Skip to Readme]
Versions [faq]
Change log
Dependencies base (>=4.7 && <5), Cabal (>= && <2.5), containers (>= && <0.7), template-haskell (==2.14.*) [details]
License BSD-3-Clause
Copyright 2019 Matej Nižník
Author Matej Nižník
Category Language
Source repo head: git clone
Uploaded by TheMatten at 2020-02-02T17:37:08Z
Distributions NixOS:
Downloads 231 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-02-02 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for first-class-instances-

[back to package description]


(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!