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] 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.*) [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 Sun Feb 2 17:37:08 UTC 2020
Distributions NixOS:0.1.0.0
Downloads 114 total (45 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]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


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!