Docstoc

assign

Document Sample
assign Powered By Docstoc
					F22HW3 Prototyping from Specification – Assignment 2007/8

The assignment is based on the following specification of a Blog system

The basic types are:

[PERSON]               the set of all possible unique people

Posts by the Blog owner have unique numbers:


      posts : 

     posts = {...}


Someone may respond to a post if they are registered as responders and they identify
which post they are responding to. Responses have unique numbers allocated by the
system:

            Blog

       responders:  PERSON
       responses:  (PERSON  )
       responseTo:   
       nextResponse: 


      dom responses  responders
      r  ran responses  r < nextResponse
      ran responses = dom responseTo
      ran responseTo  posts




Initially, there are no responders or responses, and no unique numbers have been
allocated:
          Init
      Blog’

     responders = {}
     responseTo = {}
     responses = {}
     nextResponse = 0
Someone may become a responder if they are not already a responder:

          NewResponder
       Blog
       p? : PERSON


       p?  responder
       responder’ = responder  {p?}
       responses’ = responses
       responseTo’ = responseTo
       nextResponse’ = nextResponse



Someone may post a response if they are a responder, they have identified a valid post
and they have not responded to that post already. Their response is given the next free
response number and the next free response number is incremented:

        Response
     Blog
     p? : PERSON
     n? : 

     p?  responder
     n?  posts
      ( nr  ran responses  (p?  nr)  responses  (nr n?)  responseTo)
     responder’ = responder
     responses’ = responses {(p?  nextResponse)}
     responseTo’ = responseTo {(nextResponse  n?)}
     nextResponse’ = nextResponse+1


It is possible to find all the people who responded to a post:

          GetResponders
     Blog
    p? : 
    r! :  PERSON

     p?  posts
     r! = dom (responses  dom ( responseTo  {p?}))




It is possible to find all the posts to which a responder has responded:
        GetPosts
     Blog
    r? : PERSON
    p! :  

     r?  responders
     p! = responseTo  ran ({r?}  responses) 


The messages are:

MESSAGE ::= success | alreadyResponder | notResponder |
            notPost | alreadyResponded

To produce the success message:

Success  [message!: MESSAGE | message! = success]

If someone is already a responder:

        AlreadyResponder
    Blog
   p? : PERSON
   m! : MESSAGE

    p?  responders
    m! = alreadyResponder


If someone is not a responder:
       NotResponder
   Blog
  rp? : PERSON
  m! : MESSAGE

    r?  responders
    m! = notResponder


If a post number is not valid:
     NotPost
   Blog
  n? : 
  m! : MESSAGE

    n?  posts
    m! = notPost
If someone has already responded to a post:


       AlreadyResponded
     Blog
    p? : PERSON
    n? : 
    m! : MESSAGE


      nr  ran responses  (p?  nr)  responses  (nr n?)  responseTo
     m! = alreadyResponded



The total schema are:

NEW  (NewResponder  Success)  AlreadyResponder
RESPONSE  (Response  Success)  NotResponder  NotPost 
            AlreadyResponded
GETRESPONDERS  (GetResponders  Success)  NotPost
GETPOSTS  (GetPosts  Success)  NotResponder

Construct a SML prototype from this specification. You should:

a) define types for PERSON, and the elements of posts, responders, responses and
responseTo.

b) write a function to evaluate Blog as an assertion

c) write a function for Init

d) write functions for the preconditions and operations of NewResponder, Response,
GetResponders and GetPosts

e) define a type for MESSAGE

f) write functions for AlreadyResponder, NotResponder, NotPost and
AlreadyResponded

g) implement the final schemas as one function which given an action argument from:

        EVENT ::= NEWR | RESPONSE | GETR | GETP

a  PERSON for responders, a  (PERSON ) for responses, a  ( ) for
responseTo and other appropriate input parameters, updates responders, responses,
responseTo and message , and other appropriate outputs.

h) write a function which checks the assertion from b), uses the function from g) to
change state and checks the assertion from b)
Test your prototype with an initial set of two posts.

You should submit a report consisting of:

i) a brief description of the problem

ii) commented SML

iii) convincing test cases

iv) brief discussion of how this approach compares with your favourite approach to
constructing software

by 5pm on Friday 6th June.

You should not spend more than 30 hours on this project.

Greg Michaelson 23/4/8

				
DOCUMENT INFO
Categories:
Tags:
Stats:
views:4
posted:3/10/2012
language:
pages:5