conjure-cp / conjure

Conjure: The Automated Constraint Modelling Tool
Other
96 stars 20 forks source link

xmatch question #16

Closed ozgurakgun closed 7 years ago

ozgurakgun commented 11 years ago

Originally reported by: Bilal Hussain (Bitbucket: Bilalh, GitHub: Bilalh)


When using xMatch on b5.essence

language ESSENCE 2.0

letting sol be [0,1]
find x : int(0..9)

such that
    x != 1

I can get the such that part by using

let Spec _ statements = spec
let res = [ (x) | x@[xMatch|  [Tagged a b] := topLevel.suchThat|] <- statements ]

and the declaration by using

let res = [ (x) | x@[xMatch|  [Tagged a b] := topLevel.declaration|] <- statements ]

why does

let res = [ (x) | x@[xMatch|  [Tagged a b] := topLevel.letting|] <- statements ]

return no results

b5.essence haskell representation

#!haskell
Spec ("ESSENCE",[2,0]) [Tagged "topLevel" [Tagged "letting" [Tagged "name"
[Tagged "reference" [Prim (S "sol")]],Tagged "expr" [Tagged "value" [Tagged
"matrix" [Tagged "values" [Tagged "value" [Tagged "literal" [Prim (I
0)]],Tagged "value" [Tagged "literal" [Prim (I 1)]]]]]]]],Tagged "topLevel"
[Tagged "declaration" [Tagged "find" [Tagged "name" [Tagged "reference" [Prim
(S "x")]],Tagged "domain" [Tagged "domain" [Tagged "int" [Tagged "ranges"
[Tagged "range" [Tagged "fromTo" [Tagged "value" [Tagged "literal" [Prim (I
0)]],Tagged "value" [Tagged "literal" [Prim (I 9)]]]]]]]]]]],Tagged "topLevel"
[Tagged "suchThat" [Tagged "binOp" [Tagged "operator" [Prim (S "!=")],Tagged
"left" [Tagged "reference" [Prim (S "x")]],Tagged "right" [Tagged "value"
[Tagged "literal" [Prim (I 1)]]]]]]]

ozgurakgun commented 11 years ago

Original comment by Özgür Akgün (Bitbucket: ozgurakgun, GitHub: ozgurakgun):


Not a bug, but a question.

ozgurakgun commented 11 years ago

Original comment by Özgür Akgün (Bitbucket: ozgurakgun, GitHub: ozgurakgun):


This isn't a bug.

Save the following in a file and call it via:

runhaskell src/Temp.hs b5.essence

{-# LANGUAGE QuasiQuotes, ViewPatterns, OverloadedStrings #-}

import Language.E
import Language.E.Pipeline.ReadIn
import System.Environment(getArgs)

main :: IO ()
main = do
    args <- getArgs

    specFilename <- case filter (".essence" `isSuffixOf`) args of
                        [t] -> return t
                        _   -> error "Only 1 *.essence file."

    specPair  <- pairWithContents specFilename

    [spec ]   <- runCompEIO (readSpec specPair)

    let lettings = [ x | let Spec _ xs = spec
                       , x@[xMatch| _ := topLevel.letting |] <- xs
                       ]

    mapM_ (print . pretty) lettings
    mapM_ print lettings

(Also update your repo NOW, because I created a branch by mistake and merged it back with yours.)