Я не могу выровнять типы в последней функции. Суть в том, чтобы установить все ценовые удвоения в соединениях с функцией, которая зависит только от индекса тройки. Исходное значение 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