Hi all,
I’m playing around with heterogeneous list types, vaguely inspired by the Vinyl librairies records.
Most of it works fine, but I struggle a bit finding out good ways to map over the heterogeneous types in the list—understandably because GHC somehow needs to know what functions I can apply to them—and to filter out certain types and convert to a homogeneous regular list.
Here is what I have, with the latter functions just pseudocode because I don’t know how to best implement them:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs #-}
module Main where
data HL :: [*] -> * where
HNil :: HL '[]
(:&) :: !r -> !(HL rs) -> HL (r ': rs)
infixr 7 :&
a :: HL '[Double, String, Double]
a = 3.0 :& "hey" :& 1.0 :& HNil
-- how can I implement the following "filter", "convert" and "mult" functions?
b :: HL '[Double, Double]
b = filter (Proxy @Double) a
c :: [Double]
c = convert b
mult :: HL xs -- where all elements x of xs fullfill the Num x constraint.
mult x = hlmap (*2) x
Any ideas how to best do this?