Skip to content

Instantly share code, notes, and snippets.

@DougBurke
Created March 8, 2015 14:02
Show Gist options
  • Save DougBurke/04a7fc91f18b321845f7 to your computer and use it in GitHub Desktop.
Save DougBurke/04a7fc91f18b321845f7 to your computer and use it in GitHub Desktop.
See @gibiansky/IHaskell#367
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"hidden": false
},
"outputs": [],
"source": [
":set -XTypeFamilies\n",
":set -XDataKinds"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import Data.Metrology\n",
"import Data.Metrology.SI\n",
"import Data.Metrology.Show"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data AngleDim = AngleDim\n",
"data Radian = Radian\n",
"\n",
"instance Dimension AngleDim where\n",
" type DimFactorsOf AngleDim = '[]\n",
"\n",
"type instance DefaultUnitOfDim AngleDim = Radian\n",
"\n",
"instance Unit Radian where\n",
" type BaseUnit Radian = Canonical\n",
" type DimOfUnit Radian = AngleDim\n",
" type UnitFactorsOf Radian = '[]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.3"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"0.3 % Radian"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"instance Show Radian where\n",
" show _ = \"rad\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.3"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"0.3 % Radian"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"hidden": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"name": "haskell",
"version": "7.8.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment