-
-
Save zyklotomic/d1e7eb54e74ea53dcb9a5f616d362dc8 to your computer and use it in GitHub Desktop.
Deduce Type from Parameter? GHC extension?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
module Histogram where | |
-- Hide Prelude due to VegaLite conflicts | |
import Graphics.Vega.VegaLite as VL | |
import Prelude hiding (filter, lookup, repeat) | |
class (Show a, Ord a, Eq a, Enum a, Bounded a) => VegaEncodable a | |
-- Requires RankNTypes | |
type CountMap a = (VegaEncodable a) => a -> Double | |
toHistogram :: CountMap a -> VegaLite | |
toHistogram v = _ -- is there a way to deduce the type of v? | |
-- so that I can for example do map [minBound::${type of v}..maxBound::${type of v}] | |
-- Part 2, is the type constraint in CountMap not enough to infer `a` is VegaEncodable? | |
-- this compiles | |
f :: (VegaEncodable a) => CountMap a -> [Double] | |
f cm = map cm [minBound..maxBound] | |
-- but this does not | |
f' :: CountMap a -> [Double] | |
f' cm = map cm [minBound..maxBound] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment