Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gelisam/hs-promote
C++-style type promotion for Haskell's numeric hierarchy
https://github.com/gelisam/hs-promote
Last synced: 22 days ago
JSON representation
C++-style type promotion for Haskell's numeric hierarchy
- Host: GitHub
- URL: https://github.com/gelisam/hs-promote
- Owner: gelisam
- Created: 2013-03-31T20:47:04.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-22T00:10:47.000Z (over 9 years ago)
- Last Synced: 2023-04-13T07:57:02.778Z (over 1 year ago)
- Language: Haskell
- Size: 137 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Type promotion in haskell
=========================Like in Haskell, the arithmetic operations of C++ always act on identical types (ex: 2 + 2 or 2.0 + 2.0, but not 2 + 2.0).
Unlike Haskell, C++ automatically promotes the arguments of arithmetic operations to the most general type. Lest it be thought that C++ is superior to Haskell in this regard, here is an implementation of type promotion in Haskell.
Implementation
--------------I use type families to compute the resulting type, e.g. Promote Int Double = Double because the result of 2 + 2.0 is a Double.
One downside of this implementation strategy is that we need to define a quadratic number of instances, one for each pair of compatible types. To avoid doing this, I use Template Haskell to generate all the instances.