【发布时间】:2020-03-09 20:31:02
【问题描述】:
我无法让最后一个函数中的类型对齐。重点是设置与仅依赖于 3 元组索引的函数相关的所有价格双倍。元组中原来的 Double 值可以丢弃。
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
import Control.Lens
data Typex = Typex
{ _level :: Int
, _coordinate :: (Int, Int)
, _connections :: [(Int, (Int, Int), Double)] -- = (level, coordinate, price)
} deriving Show
makeLenses ''Typex
initTypexLevel :: Int -> Int -> Int -> [Typex]
initTypexLevel a b c = [ Typex a (x, y) [(0,(0,0),0.0)]
| x <- [0..b], y <- [0..c]
]
buildNestedTypexs :: [(Int, Int)] -> [[Typex]]
buildNestedTypexs pts
= setConnectionsx [ initTypexLevel i y y
| (i,(_,y)) <- zip [0..] pts
]
setConnectionsx :: [[Typex]] -> [[Typex]]
setConnectionsx (x:rest@(y:_)) = map (connect y) x : setConnectionsx rest
where connect :: [Typex] -> Typex -> Typex
connect txs tx
= tx & connections .~ (map ((tx ^. level) + 1, , 0.0) $ txs ^.. traverse.coordinate)
setConnectionsx lst = lst
setInitPrices :: [[Typex]] -> [[Typex]]
setInitPrices (x:rest) = map setIndexPrices x : setInitPrices rest
where setIndexPrices :: Typex -> Typex
setIndexPrices tx = n & connections .~ ??? -- using iset (?), set the price in every 3-tuple so that price = f (index of the 3-tuple) where f = i*2
setInitPrices lst = lst
【问题讨论】:
标签: haskell indices haskell-lens custom-data-type