0

Theoretically my function should be able to return True or False if a set of clauses has the empty list ([]), I actually defined the next data type:

data Literal = V String | NotV String deriving Eq
type Clause = [Literal]
type Interpretacion = [( String , Bool ) ]
type State = ( Interpretation , [ Clause ])

And for the function i did this:

conflict :: State -> Bool
    | [] `elem` xs = True
    | otherwise = False

But i really think that this is not going to be enough, my next work is do another function that determines if the model search has been successful, (this happens when the clause set is empty), I think that I have to use the above function using the same (State -> Bool) but if the first function is not working the second can't work either.

My big question is: What do you think I need to do?. Any comment will be of great help to me, I'm a little lost. My work is about the transition rules from DPLL algorithm, once i have i'm going to share in Github to new programmers.

John M.
  • 1
  • 1
  • If `State` and `Estado` are the same thing, then this does not do what you think it does. ```x `elem` (y, z)``` means `x == z`. See also: [Why does length return 1 for a tuple with 2 elements?](https://stackoverflow.com/q/36460833/791604) – Daniel Wagner Mar 18 '23 at 01:44
  • I have voted to close. I think "What do I need to do?" is too broad to be answerable. Only you can know what algorithm you want to implement. A question like "I apply `conflict` to `X` and get `Y` but need to get `Z`" is concrete and answerable. But after reading this question several times, I still do not know why the current implementation of `conflict` is not suitable. – Daniel Wagner Mar 18 '23 at 01:53
  • @DanielWagner I agree with your main point, but I think you and I can both see at least two reasons why `conflict` fails to compile, which surely goes towards being unsuitbale. – amalloy Mar 18 '23 at 03:00

1 Answers1

1

I think I've seen the same problem on another site when implementing the DPLL algorithm, maybe you could try using a function like this:

isEmptyState :: State -> Bool
isEmptyState = null . assignments

And for the next function you could implement a helper function that checks the first function and another that returns the result of it, like this:

unassigned :: State -> [Var]
unassigned (State(_,us)) = us

complete :: State -> Bool
complete = null . unassigned

I think the point you're trying to get to with the first function is that when you compile you can have something like this:

ghci >success ([( p , True ) , (q , False ) ] , []) ▷ True
  • Yes, you're right in the compilation, that's what I'm trying to do, I would have to do some fixing but I think it could work, thanks. – John M. Mar 18 '23 at 02:24