map - Trying to make the wireworld move by fmap (transition) but it shows me an error somehow (Haskell) -


the same last question, im asked make wireworld ordered lists, have written following codes,(all of function in code somehow defined in other modules, so, dont worry xd, feel free ask me if u want have @ "predefined funcs") when run on terminal, shows error, here code:

module transitions.for_ordered_lists_2d (    transition_world -- :: ordered_lists_2d cell -> sparse_line cell )  import data.cell (cell (head, tail, conductor, empty)) import data.coordinates import data.ordered_lists_2d   -- replace function more meaningful:   xandy :: element_w_coord cell -> coord xandy (e, (x, y)) = (x, y)  transition_sc :: ordered_lists_2d cell -> placed_elements cell -> sparse_line cell transition_sc world pec = case world of sparse_line{y_pos = y, entries =  xline}: rest_of_sparse_lines  -> case pec of         placed_element{x_pos = x, entry =  head} : rest_of_placed_elements   -> (sparse_line{y_pos = y, entries = placed_element{x_pos = x, entry =  tail} :  rest_of_placed_elements})          placed_element{x_pos = x, entry =  tail} : rest_of_placed_elements   -> (sparse_line{y_pos = y, entries = placed_element{x_pos = x, entry =  conductor} : rest_of_placed_elements})          placed_element{x_pos = x, entry =  empty} : rest_of_placed_elements   -> (sparse_line{y_pos = y, entries = placed_element{x_pos = x, entry =  empty} : rest_of_placed_elements})          placed_element{x_pos = x, entry =  conductor} : rest_of_placed_elements             |element_occurrence head neighbours == 1 || element_occurrence head neighbours == 2    -> (sparse_line{y_pos = y, entries = placed_element{x_pos = x, entry =  head} : rest_of_placed_elements})              |otherwise                                                                             -> (sparse_line{y_pos = y, entries = placed_element{x_pos = x, entry =  conductor} : rest_of_placed_elements})                                      neighbours = local_elements (xandy (conductor, (x, y))) world   transition_world :: ordered_lists_2d cell -> ordered_lists_2d cell transition_world world = fmap (transition_sc world) world        --the end --the end --the end 

however shows me following error:

u5363876@n114lt20:~/desktop/lalal$ ./make_wireworld [10 of 20] compiling transitions.for_ordered_lists_2d ( sources/transitions/for_ordered_lists_2d.hs, x86_64/transitions/for_ordered_lists_2d.o )  sources/transitions/for_ordered_lists_2d.hs:35:53:     couldn't match expected type `placed_elements cell'                 actual type `sparse_line cell'     expected type: [placed_elements cell]       actual type: ordered_lists_2d cell     in second argument of `fmap', namely `world'     in expression: fmap (transition_sc world) world 

im totally confused error thank in advance can me.

@dave4420 here definition placed_elements , sparse_lines

type ordered_lists_2d e = [sparse_line e]  data sparse_line e = sparse_line {y_pos :: y_coord, entries :: placed_elements e}  data placed_element  e = placed_element {x_pos :: x_coord, entry :: e} type placed_elements e = [placed_element e] 

you have strange case

don't use

case pec of     placed_element{x_pos = x, entry =  head} : rest_of_placed_elements   -> ... 

use instead

case entry (head pec) of     head   -> ... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -