acowley / Frames

Data frames for tabular data.
Other
298 stars 41 forks source link

declareColumn type should override tableTypes #66

Open codygman opened 7 years ago

codygman commented 7 years ago

Code

{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
module TestDouble where

import Frames
import Frames.CSV
import Data.Vinyl
import Control.Monad.IO.Class
import qualified Pipes as P
import qualified Pipes.Prelude as P

declareColumn "col_c" ''Double
tableTypes' rowGen "test.csv"

expected type

type Row =
  Record '["col_a" :-> Int, "col_b" :-> Int, "col_c" :-> Double]

actual type after attempting (but probably failing to ensure) column types aren't created if existing

type Row =
  Record '["col_a" :-> Int, "col_b" :-> Int, "col_c" :-> Bool]
acowley commented 7 years ago

The Row definition isn't using unique type names for the columns, so the recent patch to look up type names before defining them won't prevent this. I like this way of fixing the inference, though, so it's worth taking a look to see if we can do the name lookups before the Row definition and swap in the existing definition if found. Could be tricky.

acowley commented 7 years ago

How about we use something like this, perhaps with my TypeApplications suggestion? I can't think of a good way of doing the type lookup thing to allow the override.