-- | functions to help making lists for consumption on the R side
module RlangQQ.MakeRecord where

import GHC.TypeLits -- prevents a panic lookupVers2 <<details unavailable>> with ghc 7.6. Fixed later probably from #7502
import Data.HList.CommonMain
import Control.Lens


-- | convert a haskell list into a record with labels all of type \"\". The length
-- of the list is decided by the (type of the) first argument which is a 'HNat'
--
-- > listToRecN :: _ => Proxy (n :: HNat) -> [x] -> Record (HReplicateR n (Tagged "" x))
listToRecN n xs = maybe (error msg) (`asTypeOf` es)
                  $ xs ^? listAsHList . from unlabeled

  where es = (undefined :: Proxy n -> [x] -> Record (HReplicateR n (Tagged "" x)))
                n xs
        msg = "RlangQQ.listToRecN too few elements"