Skip to content

Instantly share code, notes, and snippets.

@mchav
Created September 6, 2025 04:29
Show Gist options
  • Select an option

  • Save mchav/8cae930a64a3ae8191583525772738da to your computer and use it in GitHub Desktop.

Select an option

Save mchav/8cae930a64a3ae8191583525772738da to your computer and use it in GitHub Desktop.
A minimal definition of a columnar dataframe with a closed.
module DataFrame where
-- Column space with a closed type universe.
data Column = CInt [Int]
| CDouble [Double]
| CString [String]
instance Show Column where
show (CInt xs) = show xs
show (CDouble xs) = show xs
show (CString xs) = show xs
class ToColumn a where
fromList :: [a] -> Column
instance ToColumn Int where fromList = CInt
instance ToColumn Double where fromList = CDouble
instance ToColumn String where fromList = CString
class Transform a b where
transform :: (a -> b) -> Column -> Column
instance Transform Int Int where
transform f (CInt xs) = fromList (map f xs)
instance Transform Int Double where
transform f (CInt xs) = fromList (map f xs)
instance Transform Int String where
transform f (CInt xs) = fromList (map f xs)
instance Transform Double Int where
transform f (CDouble xs) = fromList (map f xs)
instance Transform Double Double where
transform f (CDouble xs) = fromList (map f xs)
instance Transform Double String where
transform f (CDouble xs) = fromList (map f xs)
instance Transform String Int where
transform f (CString xs) = fromList (map f xs)
instance Transform String Double where
transform f (CString xs) = fromList (map f xs)
instance Transform String String where
transform f (CString xs) = fromList (map f xs)
data DataFrame = DataFrame {
columns :: [(String, Column)]
} deriving (Show)
fromNamedColumns :: [(String, Column)] -> DataFrame
fromNamedColumns = DataFrame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment