Author: Harsh Raj Singh (250847420)
This project implements a concurrent social network simulation using Advanced Functional Programming techniques. It models 10 independent user threads interacting via message passing, designed to demonstrate High-Assurance software architecture.
Unlike standard implementations, this project uses:
- Software Transactional Memory (STM) for deadlock-free concurrency (replacing raw
MVars). - Tagless Final style to decouple pure logic from IO effects.
- Type-Level States (GADTs) to make invalid agent states unrepresentable.
- Mood Propagation Dynamics: Users are emotional agents. Their internal mood (
Happy,Neutral,Sad) evolves based on the "Vibe" of messages received, creating a dynamic feedback loop.- Effect: Mood influences both the content of sent messages and the response latency (simulating human reaction times).
- Log Parsing & Analytics: A custom
Megaparsecgrammar parses the simulation logs to generate an ASCII Pie Chart of the final network mood distribution, verifying the propagation mechanics.
The application uses a CLI for various operations:
-
Run Simulation (Default):
stack run
Executes the simulation (10 users, 100 messages) and prints the final message counts.
-
Analyze Log (Visualization):
stack run -- analyze-log
Parses the generated
social_network_chat.logand displays the Mood Distribution Pie Chart. -
View Log/Help:
stack run -- view-log stack run -- help
The project employs Property-Based Testing (QuickCheck) to verify invariants (e.g., algebraic laws for counters, round-trip correctnes for parsers).
- Run All Tests:
stack test - Check Code Coverage:
(Open the generated HTML report in
stack test --coverage.stack-work/.../hpc/index.htmlto verify 100% coverage of pure logic modules).
- app/Main.hs: CLI Entry point.
- src/Run.hs: Simulation wiring and Supervisor.
- src/Config.hs: Global simulation constants.
- src/UserBehaviour.hs: Core "Brain" logic (Pure).
- src/Types.hs: Domain types (User, Message, Monoids).
- src/Env.hs: Runtime environment context.
- src/Effects.hs: Abstract Effect capability definitions.
- src/AppM.hs: Concrete interpreter (ReaderT Env IO).
- src/Logger.hs: Concurrent logging service.
- src/LogParser.hs: Parsing logic for analytics.
- test/Spec.hs: Test suite (Properties & Unit tests).