diff --git a/README.md b/README.md index 6c3692a..1e27f6c 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,10 @@ values, that can be much faster. ## Changelog -version 0.2.2.0 (2024-11-05): +version 0.2.3.0 (2024-11-05): * Updates the testing and benchmarking framework. +* Replaced benchmarking dependencies, making the build process much faster. +* Added an example teacher, and run script. version 0.2.0.0 (2024-11-01): * Resolves compiler warnings. diff --git a/app/Teacher.hs b/app/Teacher.hs new file mode 100644 index 0000000..9a9f62e --- /dev/null +++ b/app/Teacher.hs @@ -0,0 +1,29 @@ +import System.IO (hFlush, stderr, stdout, hPutStrLn) + +-- TODO: Actually implement interesting languages... Not sure yet how I want +-- to do equivalence queries. Maybe let the teacher respond with a test +-- query to the learner? +main :: IO () +main = do + messages <- lines <$> getContents + mapM_ act messages + where + act message = + case message of + "ALPHABET" -> handleAlphabet + str -> case take 2 message of + "MQ" -> handleMQ (drop 3 message) + "EQ" -> handleEQ (drop 3 message) + handleAlphabet = do + putStrLn "ATOMS" + hFlush stdout + handleMQ str = do + -- accepts any string + putStrLn "Y" + hPutStrLn stderr $ "MQ received: " <> str + hFlush stdout + handleEQ str = do + -- immediately accepts the hypothesis + putStrLn "Y" + hPutStrLn stderr $ "EQ received: " <> str + hFlush stdout diff --git a/ons-hs.cabal b/ons-hs.cabal index c2e45ca..12506de 100644 --- a/ons-hs.cabal +++ b/ons-hs.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: ons-hs -version: 0.2.2.0 +version: 0.2.3.0 synopsis: Implementation of the ONS (Ordered Nominal Sets) library in Haskell description: Nominal sets are structured infinite sets. They have symmetries which make them finitely representable. This library provides basic manipulation of them for the total order symmetry. It includes: products, sums, maps and sets. Can work with custom data types. homepage: https://github.com/Jaxan/ons-hs @@ -55,6 +55,17 @@ executable ons-hs-lstar ExampleAutomata, IO +executable ons-hs-teacher + import: stuff + hs-source-dirs: app + main-is: Teacher.hs + build-depends: + mtl, + ons-hs + other-modules: + ExampleAutomata, + IO + executable ons-hs-minimise import: stuff hs-source-dirs: app diff --git a/run-lstar.sh b/run-lstar.sh new file mode 100755 index 0000000..74390d2 --- /dev/null +++ b/run-lstar.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Example usage of how to run lstar against a non-interactive teacher. This +# script will create two fifos for the learner and teacher to communicate over. +# The communication is not visible, only output to stderr will be shown in +# the terminal + +# safety flags, remove x if you don't like all the output +set -euxo pipefail + +# create temporary directory, and names for the fifo queues (not files) +tempdir=$(mktemp -d run-lstar.temp.XXXXXX) +queryfifo="$tempdir/queries" +answerfifo="$tempdir/answers" + +# find the binary for the learner and teacher. +# The haskell project must be built beforehard (cabal build all) +lstar=$(cabal list-bin ons-hs-lstar) +teacher=$(cabal list-bin ons-hs-teacher) + +# make the connection for the processes +mkfifo $queryfifo $answerfifo + +# run the teacher in the background +$teacher < $queryfifo > $answerfifo & + +# run the learning algorithm, measuring its time +time $lstar > $queryfifo < $answerfifo + +# clean up +rm -r $tempdir