Skip to content

Melt Demo Does Not Compile #186

@idontgetoutmuch

Description

@idontgetoutmuch

I have this which does compile but maybe it is not what you had in mind

{-# LANGUAGE DataKinds, QuasiQuotes, TypeOperators #-}
module Melt where
import Control.Applicative
import Data.Foldable (toList)
import Frames
import Data.Vinyl.CoRec
import           Data.Vinyl.TypeLevel as V
import qualified Data.Vinyl as V
import qualified Data.List as L


type Age = "age" :-> Int
type Weight = "weight" :-> Double
type Name = "name" :-> String

testRec1 :: Record '[Name, Age, Weight]
testRec1 = "bob" &: 23 &: 75.2 &: V.RNil

testRec2 :: Record '[Name, Age, Weight]
testRec2 = "alice" &: 34 &: 55.2 &: V.RNil

testMelt :: Record '[Name, Age, Weight] -> [Record ('[Name, Val])]
testMelt = meltRow [pr1|Name|]

type Val = "value" :-> CoRec ElField '[Age, Weight]

testField :: [Record '[Name, Val]]
testField = filter
              ((== 0) . variantIndexOf . rgetField @Val)
              (testMelt testRec1)

molten :: [Record '[Name, Val]]
molten = toList (melt [pr1|Name|] (toFrame [testRec1, testRec2]))

testField1 :: [Record '[Name, Val]]
testField1 = filter
               ((== 0) . variantIndexOf . rgetField @Val)
               molten

testField2 :: [Record '[Name, Val]]
testField2 = filter
               ((> (Just 60.0 :: Maybe (ElField Weight))) . asA' . rgetField @Val)
               molten

main = do
  putStrLn $ (L.intercalate "\n" $ fmap show $ molten)
  putStrLn "Test"
  putStrLn $ (L.intercalate "\n" $ fmap show $ testField)
  putStrLn "Test 1"
  putStrLn $ (L.intercalate "\n" $ fmap show $ testField1)
  putStrLn "Test 2"
  putStrLn $ (L.intercalate "\n" $ fmap show $ testField2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions