haskell - Is it possible to represent this transformation in a strongly typed manner? -
i'm looking perform transformation (in f#):
type test = tbool of bool | tstring of string type testlist = tlbool of bool list | tlstring of string list let transform : map<int, test> list -> map<int, testlist> = ??
is there way encode such "know" while map contains heterogeneous values, value @ each position same type across elements of containing list? maps of static size once constructed , same across each list element, size not known in advance i'm looking generate tuples/records of unknown size.
edit
i think example unclear. root of i'm after able take 2 variable sized collections values @ given position same type, collection can contain values of multiple types, , "zip" them using knowledge @ given position 2 values same type. specifically, don't want have recheck same , propagate condition vary (as error of sort), since when creating collections.
edit 2
from comment posted below: want heterogenous lists (i used maps since indices can sparse, use lists index mapping), additional constraint 2 instances of heterogenous list can "zipped together" , values @ given index of same type.
edit [...] root of i'm after able take 2 variable sized collections values @ given position same type, collection can contain values of multiple types, , "zip" them using knowledge @ given position 2 values same type.
this, in broadest reading, fundamentally requires types of collections encode position contains element type, , dips dependent types territory.
if there 1 fixed shape of collection can determined @ compilation time, however, it's easy—you write type of values have shape.
Comments
Post a Comment