functional programming - Elm function with the type: Signal (List a) -> List (Signal a) -
i new elm , functional programming in general. using elm , need function has signal (list string) input , returns list (signal string).
i know shouldn't have problem better architectural design in program having function solve big problem me.
the combine function opposite:
combine : list (signal a) -> signal (list a) combine = list.foldr (map2 (::)) (constant [])
i've tried similar combine function have been unsuccessful far. ideas on how create such function?
this not possible in general
the inverse of combine
not (in general) possible.
when have list of static size of signals, can combine
them signal of lists of static size. when go other way, there no guarantee lists in signal static size. therefore cannot "just" construct list out of it.
(if normal value of type list
have changing size without showing signal
around type, , dynamically creating , destroying signals in list. 2 things elm disallows. )
but restrictions...
of course if you know list in signal of static size, can write specific function based on assumption; function fail @ runtime if case occurs assumption of static size lists wrong.
unsafe : maybe -> unsafehead m = case m of -> nothing -> debug.crash "unsafe: you're out of luck. `maybe` not `just`. " uncombine : int -> signal (list a) -> list (signal a) uncombine n sig = if n == 0 [] else signal.map (list.head >> unsafe) sig :: uncombine (n-1) (signal.map (list.tail >> unsafe) sig)
(i'm quite sure question discussed on elm-discuss mailing list once, can't find more)
Comments
Post a Comment