Skip to content

Instantly share code, notes, and snippets.

@zyklotomic
Last active June 16, 2021 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyklotomic/d1e7eb54e74ea53dcb9a5f616d362dc8 to your computer and use it in GitHub Desktop.
Save zyklotomic/d1e7eb54e74ea53dcb9a5f616d362dc8 to your computer and use it in GitHub Desktop.
Deduce Type from Parameter? GHC extension?
{-# 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