I’m sure there are lots of problems/sub-optimal things in this code (like that funny destructureIt
that needs to go) and all comments are welcome, but I’m currently stuck on why in partToText
, partId
is an Int
as expected but cost
is a RobotPart -> Double
instead of just a Double
?
data RobotPart = RobotPart
{
partId :: Int
, name :: T.Text
, description :: T.Text
, cost :: Double
} deriving Show
destructureIt :: Either a1 (a2, b) -> a2
destructureIt (Right (a,b)) = a
toRobotPart :: [T.Text] -> RobotPart
toRobotPart part = RobotPart {
partId = a0
, name = a1
, description = a2
, cost = a3
}
where a0 = destructureIt (TR.decimal (head part))
a1 = part !! 1
a2 = part !! 2
a3 = destructureIt (TR.double (part !! 3))
numToText :: (Num a, Show a) => a -> T.Text
numToText num = T.pack (show num)
partToText :: RobotPart -> T.Text
partToText RobotPart{partId=partId, name=name, description=description, cost=const} = T.concat [numToText partId, name, description, cost]
printParts :: [RobotPart] -> String
printParts parts = "x"
main :: IO ()
main = do
let file = "/.../parts.csv"
contents <- TIO.readFile file
let p1 = T.lines contents
let p2 = tail p1
let p3 = map (T.splitOn ",") p2
let p4 = map toRobotPart p3
print p4