Difference between revisions of "Real World Applications/Event Driven Applications"

From HaskellWiki
Jump to navigation Jump to search
(Added events high/low)
Line 16: Line 16:
 
So please contribute your (clearly superior of course) alternative way to do it here: [[https://www.haskell.org/haskellwiki/Real_World_Applications] Real World Applications]
 
So please contribute your (clearly superior of course) alternative way to do it here: [[https://www.haskell.org/haskellwiki/Real_World_Applications] Real World Applications]
   
== What is an Event? ==
+
== Events in Haskell ==
   
 
In the following, I define an "Event" to be a value describing something that has happened in the past. And yes this should really be called an "Event Notification" but life is too short :-)
 
In the following, I define an "Event" to be a value describing something that has happened in the past. And yes this should really be called an "Event Notification" but life is too short :-)
 
Examples:
 
 
* A user pressed a button.
 
* A HTML message arrived.
 
* A file finished loading.
 
* A new customer has been created.
 
* An intruder has been detected.
 
 
== Events in Haskell ==
 
   
 
Here is a straightforward way to define Events in Haskell:
 
Here is a straightforward way to define Events in Haskell:
Line 34: Line 24:
 
<haskell>
 
<haskell>
 
data Event =
 
data Event =
EventUserExit -- User wants to exit
+
EventUserExit -- User wants to exit
| EventUserSave -- User wants to save
+
| EventUserSave -- User wants to save
  +
| EventUserSaveAs String
| EventUserUndo -- User wants to undo
 
| EventUserRedo -- User wants to redo
+
| EventUserUndo -- User wants to undo
 
| EventUserRedo -- User wants to redo
 
deriving(Eq,Show)
 
deriving(Eq,Show)
 
</haskell>
 
</haskell>
  +
  +
Events can be high level or low level depending on how "deep" in the system you are operating.
  +
Within a UI sub-system the events are typically low level (key pressed, window closed).
  +
In a large scale distributed system the events are typically high level business events (EventCustomerCreated <details>).
   
 
== Main ==
 
== Main ==

Revision as of 11:45, 2 July 2014

Introduction

An event driven application is an application that reacts to external events.

Examples would be:

  • A text editor that reacts to user events (key pressed, mouse moved).
  • A web server reacting to IO events (message arrived, image compression done).
  • A commercial game reacting to simulated physics events and user input.
  • A report ready for distribution.
  • A loan application having been accepted/rejected.

In the following, I will show one way to architecture a Haskell system so that it can scale from small "toy" applications to large scale "Enterprise" applications.

Please note that this is not the only way to attack the problem. So please contribute your (clearly superior of course) alternative way to do it here: [[1] Real World Applications]

Events in Haskell

In the following, I define an "Event" to be a value describing something that has happened in the past. And yes this should really be called an "Event Notification" but life is too short :-)

Here is a straightforward way to define Events in Haskell:

data Event =
    EventUserExit            -- User wants to exit
  | EventUserSave            -- User wants to save
  | EventUserSaveAs String
  | EventUserUndo            -- User wants to undo
  | EventUserRedo            -- User wants to redo
  deriving(Eq,Show)

Events can be high level or low level depending on how "deep" in the system you are operating. Within a UI sub-system the events are typically low level (key pressed, window closed). In a large scale distributed system the events are typically high level business events (EventCustomerCreated <details>).

Main

Growing the Application

  • Crash Recovery
  • Undo/Redo
  • Time
  • UI
  • Databases
  • Client/Server

Your Contribution Here

Please contribute additional/alternative ways to structure large scale Haskell applications here.

Questions and feedback

If you have any questions or suggestions, feel free to mail me.