Created
April 6, 2011 18:26
-
-
Save hodzanassredin/906215 to your computer and use it in GitHub Desktop.
naive solver for socrat problem just to check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--human "socrat" = True | |
--human "platon" = True | |
--human "a" = True | |
--human _ = False | |
--mortal x = human x | |
--wordsgen numOfChars alphabet = []:[ b++[c] | numOfChars > 0, b <-wordsgen (numOfChars-1) alphabet, c <- alphabet ] | |
--alphabet = "abcdefghijklmnopqrstuvwxyz" | |
--whoIs f = take 2 [x | x <- wordsgen 6 alphabet, f x ] | |
socrat = [("name","socrat"),("human","true")] -- every object is a triplets container | |
platon = [("name","platon"),("human","true")] -- platon is this case is id for object but [rpblem with immutable | |
getProperty propName ((key, value):t) = if key == propName then value else getProperty propName t | |
getProperty propName _ = "" | |
setProperty propName propValue obj = if (getProperty propName obj) == "" | |
then (propName, propValue):obj | |
else replaceValue propName propValue obj | |
replaceValue propName propValue ((key, value):t) = if key == propName | |
then (propName,propValue):t | |
else (key,value):(replaceValue propName propValue t) | |
replaceValue _ _ [] = [] | |
isHuman obj = if (getProperty "human" obj) == "true" then True else False | |
getName = getProperty "name" | |
isMortal x = isHuman x | |
whoAre predicate [] = [] | |
whoAre predicate (x:xs) = if (predicate x) | |
then (getName x):whoAre predicate xs | |
else whoAre predicate xs | |
whoAre isMortal [platon,socrat] | |
--["platon","socrat"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment