• Stars
    star
    182
  • Rank 211,154 (Top 5 %)
  • Language
    Haskell
  • License
    BSD 3-Clause "New...
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hydra is a full-fledged framework for building web services, multithreaded and concurrent applications with SQL and KV DB support.

Hydra Framework

All-in-one framework for writing Haskell apps which use the following features out of the box:

  • Multithreading
  • Safe STM-powered concurrency
  • KV DB functionality (Redis & RocksDB backends supported)
  • SQL DB functionality (beam incorporated, SQLite supported, PG & MySQL possible)
  • CLI apps support
  • Logging
  • Random data generation
  • Many others

With the framework, you can create complex applications which have a good maintainability, testability, simplicity, have a good structure and are easy to read and change. The key principles of the framework:

  • Layered architecture
  • Separation of concerns (interfaces, business logic, runtime and implementation)
  • Simple and convenient eDSLs
  • Testable and maintainable code

The Hydra Project

This project demonstrates the principles of Software Design and Architecture in pure Functional Programming. Hydra has several separate frameworks based on different engines for easy comparison:

  • Final Tagless engine
  • Free monad based engine
  • Church-encoded Free monad based engine

The core idea of the two Free monadic frameworks is known as Hierarchical Free Monads.

The project is a showcase for my book Functional Design and Architecture. The approaches presented in Hydra are well-described and rationalized in the book, so you may obtain even more info about best practices and ideas of how to write a good Haskell code.

Note The Free monad based framework is the most developed by functionality. I'm working on synchronizing the functionality between all the engines.

Building dependencies

Ubuntu:

$ sudo apt-get install libpq-dev librocksdb-dev

MacOS:

brew install rocksdb postgresql

Building and running

Use stack for building all the framework and apps:

$ stack build

You can also switch the optimizations off and use several threads for building:

$ stack build --fast -j4

Running a project is also simple:

$ stack exec labyrinth

To load a subproject into GHCi, use the following command:

$ stack ghci labyrinth:exe:labyrinth

Sample applications

There are several sample applications:

  • Astro app: web server (with servant) and CLI client tool which allows to track meteors (tool for astronomers).
  • PerfTestApp: an application you can run to measure the performance of the three engines.
  • PerfTestApp2: another application you can run to measure the performance of the three engines.
  • MeteorCounter: application which demonstrates the usage of STM and multithreading using three engines.
  • Labyrinth: a game about exploring the labyrinth with a CLI interactive interface.

Code samples

Sample SQL-related code

createMeteor :: MeteorTemplate -> D.SqlConn BS.SqliteM -> L.AppL MeteorId
createMeteor mtp@(MeteorTemplate {..}) conn = do
  L.logInfo $ "Inserting meteor into SQL DB: " <> show mtp

  let time = Time.UTCTime (toEnum 1) (Time.secondsToDiffTime 0)

  doOrFail
    $ L.scenario
    $ L.runDB conn
    $ L.insertRows
    $ B.insert (SqlDB._meteors SqlDB.astroDb)
    $ B.insertExpressions
          [ SqlDB.Meteor B.default_
            (B.val_ size)
            (B.val_ mass)
            (B.val_ azimuth)
            (B.val_ altitude)
            (B.val_ time)
          ]

  let predicate meteorDB
          = (SqlDB._meteorSize meteorDB     ==. B.val_ size)
        &&. (SqlDB._meteorMass meteorDB     ==. B.val_ mass)
        &&. (SqlDB._meteorAzimuth meteorDB  ==. B.val_ azimuth)
        &&. (SqlDB._meteorAltitude meteorDB ==. B.val_ altitude)

  m <- doOrFail
    $ L.scenario
    $ L.runDB conn
    $ L.findRow
    $ B.select
    $ B.limit_ 1
    $ B.filter_ predicate
    $ B.all_ (SqlDB._meteors SqlDB.astroDb)
  pure $ SqlDB._meteorId $ fromJust m

Additional materials

Checkout the following materials to learn more about he Hierarchical Free Monads approach used in Hydra:

More Repositories

1

software-design-in-haskell

Software Design in Haskell. A structured set of materials. How to build real-world applications in Haskell.
Haskell
1,063
star
2

cpp_functional_programming

List of materials about functional programming in C++
646
star
3

Functional-Design-and-Architecture

Code and materials for my book "Functional Design and Architecture"
Haskell
470
star
4

The-Voids-Of-Haskell

241
star
5

functional-declarative-design-methodology

Article: Functional Declarative Design
201
star
6

hierarchical-free-monads-the-most-developed-approach-in-haskell

Big article about Hierarchical Free Monads, the most developed approach to build real software in Haskell
Haskell
152
star
7

automatic-whitebox-testing-showcase

Automatic white-box testing with Free monads: approach description and showcase
Haskell
83
star
8

Andromeda

Haskell
72
star
9

cpp_stm_free

Composable monadic STM for C++ on Free monads
C++
70
star
10

Pragmatic-Type-Level-Design

Code and materials for my book "Pragmatic Type Level Design"
Haskell
60
star
11

stm-free

STM on Free monads
Haskell
23
star
12

Haskell-Algorithms

Learning Haskell: algorithms, data structures, mini-programs, materials, excercises
HTML
16
star
13

The-Amoeba-World

The Amoeba World game
Haskell
13
star
14

pointed-validation

Validation using pointed getters with error path tracking.
Haskell
13
star
15

GraphServer

GraphServer for Haskell code visualization
Haskell
12
star
16

software-engeneering-python

Python
11
star
17

cpp_lenses

Functional lenses on C++ (highly experimental).
C++
11
star
18

Zeplrog

Experimental Rogue-like Zero Player game in Haskell and gloss
Haskell
10
star
19

cpp_philosophers_stm

Dining philosophers task using combinatorial STM built on top of Free monad
C++
8
star
20

cpp_parsec_free

Monadic parsers library
C++
8
star
21

Amber

This is a showcase project of the functional design on C++.
C++
7
star
22

hinteractive

Engine for interactive fiction games like Zork.
Haskell
7
star
23

Adv2Game

Advanced Adventure Game on Haskell
Haskell
7
star
24

zio-free

Free monadic clone (Haskell ) of Scala's ZIO, experimental
Haskell
5
star
25

transition-graph

Transition Graph eDSL
Haskell
4
star
26

Quest-Tutorial-Code

Quest Tutorial Code for Haskell Quest Tutorial articles
Haskell
4
star
27

cpp_final_tagless

C++
3
star
28

ICFPC2011

Code and Materials for ICFPC2011
Haskell
2
star
29

stm-frp

Haskell
2
star
30

gt-money

Money library (showcase of type safe approaches)
Haskell
2
star
31

ICFPC2011-Monads

Second code variant using monad State, monad transformer and special data types (incomplete)
Haskell
2
star
32

ICFPC-2012-Hackaton

Repository for attenders of ICFPC-2012 hackaton at Jan 2015, Novosibirsk
Haskell
2
star
33

MetaLife

Haskell
2
star
34

CMLife

Functional Game of Life on C++. Uses functional declarative design and functional idioms (comonads, zippers etc.)
C++
2
star
35

cpp_functional_core

Core library for functional programming on C++ (lenses, monads, etc.)
C++
1
star
36

QST

C++
1
star
37

PureScript-Algorithms

Sandbox for PureScript test apps
PureScript
1
star
38

BigSpace-obsolete

This repository was an attempt to create good project structure on Haskell. Now it is obsolete. (See The-Amoeba-World instead).
Haskell
1
star
39

ICFPC2007

Partial implementation of Endo's morphing - training due to ICFPC 2014 is coming.
Haskell
1
star
40

haskell-exercises

Haskell
1
star
41

BigSpace-Documentation

Design documents, concept art
1
star
42

yellow-stone

Experiments
Haskell
1
star
43

TestEcho

Erlang
1
star
44

stm_samples

C++
1
star