whd
whd

Reputation: 1861

Error in function in do notation

i have such function to solve some logic riddle

iloczyny is list with such structure [((0,0),(0,1),[5,0])...] [((cords1),(cords2),[Num1,Num2])..]
kandydaci is list of all possible candidates for my solution and pola is list with all possible coordinates in my matrix.
I wanna choose one candidate and compare it with possible candidate from iloczyny then if elements are equal i wanna delete coordinates from pola and call function once again.

 zbieraj iloczyny kandydaci pola = do
      element <- kandydaci
      (a,b,[c,d]) <- iloczyny
      guard (element == (c_n' [c,d]) && (elem a pola) && (elem b pola))
      nowa <- skasuj a b pola
      rk <- delete element kandydaci -- here is erorr 
      Couldn't match type `Integer' with `[Integer]'
      In the second argument of `zbieraj', namely `rk'
      reszta <- zbieraj iloczyny rk nowa
      return ([a,b] ++ reszta)

skasuj looks just like that skasuj a b lista = delete b (delete a lista) i'm not knowledgeable in haskell and cant see whats wrong

Upvotes: 1

Views: 108

Answers (1)

Daniel Fischer
Daniel Fischer

Reputation: 183873

First, please write type signatures for your functions. That will produce better error messages, and help readers understand your code better.

However, the error is that

nowa <- skasuj a b pola
rk <- delete element kandydaci -- here is erorr 

use the monadic binding x <- monadAction, but they should be ordinary let bindings

let nowa = skasuj a b pola
    rk = delete element kandydaci

A compiling version (with appropriate definition of c_n') of the function is

zbieraj iloczyny kandydaci pola = do
      element <- kandydaci
      (a,b,[c,d]) <- iloczyny
      guard (element == (c_n' [c,d]) && (elem a pola) && (elem b pola))
      let nowa = skasuj a b pola
          rk = delete element kandydaci
      reszta <- zbieraj iloczyny rk nowa
      return ([a,b] ++ reszta)

Upvotes: 3

Related Questions