考虑以下可以找到一组坐标的代码:
data Coord = Coord { lat :: Float
, lon :: Float
}
instance FromRow Coord where
fromRow = Coord
<$> field
<*> field
findSomePoints :: Connection -> Int -> IO [Coord]
findSomePoints = undefined
然后我想为命名的坐标集定义数据类型:
data Path = Path { name :: String
, points :: [Coord]
}
instance FromRow Path where
fromRow = Path
<$> field
<*> -- PROBLEM: would like to call something like `findSomePoints conn field` here...
findPath :: Connection -> Int -> IO Path
findPath = undefined
不幸的是,我不知道如何用查询组合数据类型(在我的例子Path
中Coord
)。这样的事情是否可能(以及如何?)。