Advertisement
Guest User

Untitled

a guest
Nov 5th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.36 KB | None | 0 0
  1. //Opgave 5.1
  2. //Declare an F# function isConsistent that checks the consistency of a set of literals.
  3. //Set version, men mit dilemma er at jeg ikke formår at matche x mod sin modsætning, e.g. x er endten Neg(Prop) eller A(c)
  4. let rec isConsistentset :Set<Prop> -> bool = function
  5.     |latSet ->  let comparisonSet = Set.foldBack(fun x set -> if(x = Neg of Prop)if Set.contains x (Set.remove x latSet) then Set.add x Set.empty else set) latSet Set.empty
  6.                 if Set.intersect latSet comparisonSet <> Set.empty then false else true
  7.  
  8.  
  9. //List version af isConsistent
  10. let rec isConsistent :Prop list*Prop list -> bool = function
  11.     |[],auxlist              -> true //Base case
  12.     |Neg(A(p))::pp,auxlist   -> if List.exists(fun y -> y = A(p)) auxlist then
  13.                                                                             false
  14.                                                                           else
  15.                                                                             isConsistent(pp,A(p)::auxlist)
  16.     |A(p)::pp,auxlist        -> if List.exists(fun y -> y = A(p)) auxlist then
  17.                                                                             false
  18.                                                                           else
  19.                                                                             isConsistent(pp,A(p)::auxlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement