Monday, October 10, 2011

An idea for generating test data (3)

I told the progress making the tool was 10% but it is wrong and it is not easy.

I got some tips. I describe the tip for labeled for statement.

We can write the for statement with label and the example is following:

for1: for(int i = 0; i < 10; i++) {
  for2: for(int j = 0; j < 5; j++) {
    int k = getValue(i, j);
    if (k == 1)
      continue for1;
    else if (k == 2)
      break for1;
  }
}


But the labeled for statement is not allowed in C#. So we need to write it :

for (int i = 0; i < 10; i++) {
  for (int j = 0; j < 5; j++) {
    int k = getValue(i, j);
    if (k == 1)
      goto continue_for_for1;
    else if (k == 2)
      goto break_for_for1;
  }
continue_for_for1:
}
break_for_for1:

Tuesday, October 4, 2011

An idea for generating test data (2)

I decided to use Irony to make the tool for converting Java sources to C# sources.

It is difficult for me to use ANTLR because I cannot understand building Java AST by using ANTLR.
And I can understand building Java AST by using Irony.

I am making the tool and the progress is about 10% toward completion.

Sunday, September 25, 2011

An idea for generating test data

An idea come to me and it is that we convert the Java source to C# source and apply Pex the C# source and the generated test data is usable for original Java source.

But I don't know the tools that convert Java source to C# source.

I will make the tool by ANTLR or Irony. Which is easier to make tools?

Sunday, September 18, 2011

The arrows in Haskell

Can the arrows in Haskell considered by a category?
I will investigate it later.

Sunday, September 11, 2011

The kinds of Categories usable for computer science

I want to systematize the categories but will think later.


  • cartesian closed category
  • freyd category
  • kleisli category
  • monoidal category
  • premonoidal category
  • traced monoidal category
  • braided monoidal category
  • balanced monoidal category
  • symmetric monoidal category
  • ribbon category = tortile monoidal category
  • compact closed category

Sunday, September 4, 2011

Should the copy of variable be less?

The lambda calculus with types equals to intuitionistic logic. (from the Curry-Howard Isomorphism)
Intuitionistic logic is asymmetric and is constructive.
If we want the logic to be symmetric and constructive we should restrict the copy of assumption from the linear logic.
So we can introduce the symmetry to the calculus by the copy of variable.
I think that a symmetric structure is more beautiful than asymmetric one and symmetric one is  more maintenanceable.
So I think that it is good that we restrict the copy of variable or wrap that by a library. Is it right?

Sunday, August 28, 2011

Imperative vs Declarative (2)


My ideas are following:

  1. The events encode the operations some senses.
  2. Do we think it is convenient which the events come from external of the system or are in internal of the system. 
  3. If the events are in internal of the system how the functions relates the events.

Sunday, August 21, 2011

Saturday, August 13, 2011

Reading the book for the Alloy Analyzer

I am reading the book. It is interesting.
This book teaches me Alloy Analyzer method and it is useful to design my design supporting tool.
For example, Alloy analyzer does not distinguish an object and a set containing that one. I apply the approach to my tool.

Sunday, August 7, 2011

Design Memo

I think that the functional specification should be declarative.
But I do not know the tool supporting to declare specification.
So I am making the tool, but the progress is slow...

Sunday, July 31, 2011

The proof assistant and the model finder

Are they the dual relation?

The proof assistant is the top down.
The model finder is the bottom up.

I think it is interesting that we iteratively use them.

Sunday, July 24, 2011

Advantage of the object oriented programming

I think the advantages of the object oriented programming are following.


  1. We can easily modularize programs with the class. 
  2. We can easily commonalize the code by the inheritance.
  3. We can easily commonalize with the inversion of control by the polymorphism.
  4. We can easily read the code for the order of words with S + V + O.
  5. The type system built by the class is usable.
These are achieved effectively by thinking that the all are the objects.

Monday, July 18, 2011

Memo of my tool for aiding design of web applications (2)

It is important that we consider the constraints of the resource items.
Those must be the definition of validation for user input and other request parameters.
I want my tool aiding the viewpoint.

Sunday, July 10, 2011

Memo of my tool for aiding design of web applications

I am making the tool for aiding design  of web applications.
I think it is good that Web applications have REST architecture.
So I want my tool make easy to design in REST architecture.

Sunday, July 3, 2011

I tried re-mix.

I tried re-mix. It's interesting!
I show the example using re-mix.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Remotion.Mixins;

namespace ReMixSample
{
  [TestClass]
  public class ReMixSampleTest1
  {
    [TestMethod]
    public void TestMethod1()
    {
      ReMixSample s = ObjectFactory.Create<ReMixSample>();
      Assert.AreEqual("A", s.A());
      Assert.AreEqual(3, s.B());
    }
  }
  public class MixinSample1<T> : Mixin<T>
    where T : class
  {
    [OverrideTarget]
    public string A()
    {
      return "A";
    }
  }
  public class MixinSample2<T> : Mixin<T>
    where T : class
  {
    [OverrideTarget]
    public int B()
    {
      return 3;
    }
  }
  [Uses(typeof(MixinSample1<ReMixSample>))]
  [Uses(typeof(MixinSample2<ReMixSample>))]
  public class ReMixSample
  {
    public virtual string A() { return default(string); }
    public virtual int B() { return default(int); }
  }
}

But sadly(perhaps for the limitation of the .NET framework), the methods A and B of ReMixSample class cannot be abstract methods.
Therefore the methods need the body and it will not be significant.
So I think it's easy to understand that the methods are mixed-in if we write the body is the following unified form:
virtual {Return type} {Method name}(...) { return default({Return type}); }

Sunday, June 26, 2011

Excel-DNA

I have known the Excel-DNA recently.
That's good!

I want to know the manner of connection of Excel-DNA and WPF , Rx, etc.

This technology makes me to write "NO" VBA and it's my wish from some years ago (when C# 1.0 appeared!)... :-).

Sunday, June 19, 2011

Design Supporting Tool

I have started making a aiding to design a web and RDB-base business application.
It is a WPF application and the screen capture is below:
The background color is for test :-)

Sunday, June 12, 2011

Example of translation for Object Oriented style and Functional style.

In C#,
public class X
{
  public string S1 { get; set; }
  public string S2 { get; set; }

  public virtual string A()
  {
    return S2;
  }
}

public class Y : X
{
  public string S3 {get; set; }

  public override string A()
  {
    return S3;
  }
}

In F#,
type X = string * string
type Y = X * string
type Z =
  | X of X
  | Y of Y

let A(z : Z) =
  match z with
    | X (s1, s2) -> s2
    | Y (x, s3) -> s3

Sunday, June 5, 2011

Functional Specification

I have an idea that the specification for business requirements is able to be represented in SQL and Regular Expressions.
And I am trying to create the tools aiding to define the specification.

I am developing the tools in .NET Framework and the client application is based on WPF.
At first, I will clarify the tasks.

Sunday, May 29, 2011

Intension and Extension?

I wrote the following code.

foreach(var e1 in
  from table_1
  where table_1.field_1 == 3
  select table_1) {

  foreach(var e2 in
    from table_2
    where table_2.field_2 == e1.field_1a
    select table_2) {

    foreach(var e3 in
      from table_3
      where table_3.field_3 == e2.field_2b
      select table_3) {
      ...
    }
  }
}

But the query of that code can be written in SQL as following:

SELECT *
FROM TABLE_3,
  (SELECT *
  FROM TABLE_2,
    (SELECT *
    FROM TABLE_1
    WHERE TABLE_1.FIELD_1 = 3
    ) X
  WHERE TABLE_2.FIELD_2 = X.FIELD_1A
  ) Y
WHERE TABLE_3.FIELD_3 = Y.FIELD_2B

In the former code, the loop is expanded inside. But the SQL is expanded outside.
It is interesting but I do not know that it is significant.

Sunday, May 22, 2011

Using Xaml for design document

I got an idea that we use Xaml for design document.

For example, view/state transition diagrams, ER diagrams and flow charts etc.

I want tools to create design documents in Xaml formats.

Have such tools been yet?

Sunday, May 15, 2011

I am learning Coq.

But my learning speed is slow...

I want to apply Coq for describing application specifications.
But I do not think that I use Coq directly to describe application specifications.
I convert specifictions in natural language(but formal to some extent) to Coq language and process them by Coq.

Does it work good ?

Sunday, May 8, 2011

Comonad in Coq

I am interested in Coq.
We can use Coq for proving the satisfaction for the monad laws when we define the Monad-type structure.

I want to prove the comonad laws for stream comonad using Coq.
But it's so difficult for me... .

Sunday, May 1, 2011

Monad and Comonad

Monad is famous for the sake of Haskell.
But I think that comonad is not famous.
This site describe the Store Comonad.
I write this Store Comonad in F#.

type Store<'b, 'a> = ('b -> 'a) * 'b

let Store v b : Store<'b, 'a> = (v, b)

let extract ((v, b) : Store<'b, 'a>) = v b
let fmap (f : 'a -> 'c) ((v, b) : Store<'b, 'a>) = Store (f << v) b let duplicate ((v, b) : Store<'b, 'a>) = Store (Store v) b
let extend (f : Store<'b, 'a> -> 'c) (x : Store<'b, 'a>) = fmap f (duplicate x)

Sunday, April 24, 2011

FRP and Rx

















The sample program is following:

var obs1 = Observable.FromEvent<TextChangedEventArgs>(textBox1, "TextChanged").Select(x => ((TextBox)x.Sender).Text);
var obs2 = Observable.FromEvent<TextChangedEventArgs>(textBox2, "TextChanged").Select(x => ((TextBox)x.Sender).Text);

var obs3 = obs1.Zip(obs2, (x, y) => x + y);
obs3.Subscribe(x => {
  textBox3.Text = x;
});

I recognize that (x, y) => x + y implies TextBox3.Text = TextBox1.Text + TextBox2.Text and Zip method implies time merging.

Sunday, April 17, 2011

REST Application in Java

I build the web application in REST architecture and Java.
I want to use both struts2 rest plugin and apache wink but I don't know the manner.
For example, I don't know the description for web.xml.
I want to change the filter by file extension but I got an error.
Hmm...

Sunday, April 10, 2011

REST Architecture

I have some questions for REST architecture.

1. If we implement web application (for Web Browsers) in REST architecture and Java, we use Struts2 and REST plugin as the framework. And if we implement the CSV or XML file download function as web services, we use Apache CXF (or Apache Wink ?) as the framework.
And I want to change data format in the file name extension, for example, if you access http://.../persons/list.xml then the download data format is XML and if you access http://.../persons/list.html then the format is HTML. Can we implement that with using both Struts2 REST plugin and Apache CXF(or Apache Wink)?

2. If I realize 1. I design that the resource component returns the abstract model and the presenter component for each format changes the model to the data in each format.
But it can be possible that changing models to a format requires additional information than the abstract model.

Monday, April 4, 2011

What BTS/ITS do I use ?

I think using BTS/ITS for managing to build tools.
I know Trac and Redmine but I used Trac only.
I hear that Redmine has richer functions than Trac.
Is it good that I use Redmine?
Or do I use the other BTS/ITS?

Saturday, March 26, 2011

WPF Memo

I made mistakes in developing WPF application.

1. The context menu does not show on the canvas.
→ I needed to set the background of the canvas.

2. The data binding is failed.
→ The binding source must be the property not the field. The binding target must be the dependency properties. See the site.

3. It is failed that the data binding to a property of an object.
→ The binding path is not separated by '/' but is separated by '.'.

Monday, March 21, 2011

Monad(Kleisli triple) in C#

Monad is very powerful tool for combining functions.

The definition of Monad(Kleisli triple) is following:

C : category
T : C → C : endofunctor
A, B : objects of category C
f : morphism of category C

u : A → TA
and
for any morphism f : A → TB, a morphism f' : TA → TB exists and satisfies:
1. u' = id
2. f = f'* u
3. f : A → TB, g : B → TC, (g' * f)' = g' * f'

I show the example of the validation for given value by C# code.

I prepare the following struct:

public struct Param<A>
{
private A value;

public A Value
{
get
{
if (!IsValid)
throws new Exception();

return this.value;
}
set { this.value = value; }
}

public bool IsValid { get; set; }
}

See Param as endfunctor T.
u : A → TA is defined as Unit : A → Param<A> :

Param<A> Unit(Param<A> a)
{
return new Param<A>() { Value = a, IsValid = true, };
}

f : A → TB i.e. Param<B> Validate(B b) { ... }

A function Validate2 : Param<A> → Param<B> , which is (Validate)' :

Param<B> Validate2(Param<A> pa)
{
return (pa.IsValid
? Validate(pa.Value)
: new Param<B>() { Value = default(B), IsValid = false, });
}

If we define the following function Extend, we obtain Validate2 as Extend(Validate).

Func<Param<A>, Param<B>> Extend(Func<A, Param<B>> f)
{
return (pa => (pa.IsValid
? f(pa.Value)
: new Param<B>() { Value = default(B), IsValid = false, }));
}

I confirm Extend(Unit),

Extend(Unit)(pa) =
return (pa => (pa.IsValid
? new Param<A>() { Value = pa.Value, IsValid = true, }
: new Param<A>() { Value = default(A), IsValid = false, }));

This result pa2 = Extend(Unit)(pa) satisfies :
if pa.IsValid then pa2.IsValid and pa2.Value == pa.Value,
if not pa.IsValid then not pa2.IsValid and pa2.Value throws Exception.

i.e. Extend(Unit) is Id.

For ValidateX : A → TB and ValidateY : B → TC,
Extend(Extend(ValidateY)(ValidateX)) =
return (pa => ((Extend(ValidateY)(ValidateX))(pa)).IsValid
? (Extend(ValidateY)(ValidateX))(pa)
: new Param<C>() { Value = default(C), IsValid = false, }));
=
return (pa => ((Extend(ValidateY)(Extend(ValidateX)(pa))).IsValid
? (Extend(ValidateY)(Extend(ValidateX)(pa))
: new Param<C>() { Value = default(C), IsValid = false, }));
=
Extend(ValidateY)(Extend(ValidateX))

These are equal.

Sunday, March 13, 2011

My coding rule for C# from functional programming

1. Use conditional operator than if statement.
The following code:
if (a == 1) {
obj.X = 10;
}
else {
obj.X = 20;
}

Rewrite following code:
obj.X = (a == 1 ? 10 : 20);

Assignment should be limited.

2. Use Func delegate for modifying the action.

The following code:
int func(int a)
{
return (a == 1 ? 10 : 20);
}

Rewrite following code:
int func(Func<bool> f)
{
return (f() ? 10 : 20);
}

If necessary, make the wrapper function.

ex:
int func(int a)
{
return func(() => a == 1);
}

Saturday, March 5, 2011

metrics

I knew Sonar, it's a tool for managing code quality.
I often think the architecture of the program how I build well.
I focus the metrics and metrics represent an aspect for the program architecture.
Sonar does not show the coverage of test and Cyclomatic complexity but I think they are useful.
I want to advance software quality using these metrics.

Saturday, February 26, 2011

Reactive Programming with Events

I am reading a pdf document in the site.
It's interesting to try to integrate declarative and imperative approaches to reactive programming.
The event processing, asynchronous, concurrent and parallel programming are more and more important. I want to understand many techniques and solve the problems as simple as possible.

Sunday, February 20, 2011

Functional Reactive Programming(3)

I am studying Functional Reactive Programming(FRP).
FRP has important 2 concepts, those are Behavior and Event, and I tried to implement Behavior and Event in C#.
The result is following :


public delegate T Behavior<T>(Time t);
public delegate IEnumerable<Tuple<Time, T>> Event<T>();

public static class FrpFunctions
{
  public static Behavior<TResult> DollarStar<T, TResult>(Behavior<Func<T, TResult>> ff, Behavior<T> fb)
  {
    return new Behavior<TResult>(t => ZipWith(HaskellDollar, ff(t), fb(t)));
  }
  public static TResult HaskellDollar<T, TResult>(Func<T, TResult> f, T v)
  {
    return f(v);
  }
  public static TResult ZipWith<T1, T2, TResult>(Func<T1, T2, TResult> op, T1 arg1, T2 arg2)
  {
    return op(arg1, arg2);
  }
  public static Behavior<T> Lift0<T>(T v)
  {
    return new Behavior<T>(e => v);
  }
  public static Func<Behavior<T>, Behavior<TResult>> Lift1<T, TResult>(Func<T, TResult> f)
  {
     return b1 => DollarStar(Lift0(f), b1);
  }
  public static Func<Behavior<T1>, Behavior<T2>, Behavior<TResult>> Lift2<T1, T2, TResult>(Func<T1, T2, TResult> f)
  {
    return (b1, b2) => DollarStar(Lift1((T1 x) => (Func<T2, TResult>)(y => f(x, y)))(b1), b2);
  }
  public static Event<T> Choice<T>(Event<T> fe1, Event<T> fe2)
  {
  public static Event<T> Choice<T>(Event<T> fe1, Event<T> fe2)
  {
    return new Event<T>(() => Aux(fe1(), fe2()));
  }
  public static IEnumerable<Tuple<Time, T>> Aux<T>(IEnumerable<Tuple<Time, T>> e1, IEnumerable<Tuple<Time, T>> e2)
  {
    var en1 = e1.GetEnumerator();
    var en2 = e2.GetEnumerator();
    bool b1 = en1.MoveNext();
    bool b2 = en2.MoveNext();
    while(b1 && b2) {
      if (en1.Current.Item1.Value < en2.Current.Item1.Value){
        yield return en1.Current;
        b1 = en1.MoveNext();
      }
      else{
        yield return en2.Current;
        b2 = en1.MoveNext();
      }
    }
    while(b1){
      yield return en1.Current;
      b1 = en1.MoveNext();
    }
    while(b2){
      yield return en2.Current;
      b2 = en1.MoveNext();
    }
  }
  public static Event<Tuple<T1, T2>> Snapshot<T1, T2>(Event<T1> fe, Behavior<T2> fb)
  {
    return new Event<Tuple<T1, T2>>(() => Aux(fe(), t => fb(t)));
  }
  public static IEnumerable<Tuple<Time, Tuple<T1, T2>>> Aux<T1, T2>(IEnumerable<Tuple<Time, T1>> e1, Func<Time, T2> e2)
  {
    foreach (var v in e1) {
      yield return Tuple.Create(v.Item1, Tuple.Create(v.Item2, e2(v.Item1)));
    }
  }
  public static Event<Unit> Sharp()
  {
     return When(new Behavior<bool>(t => t.Value == 1));
  }
  public static Event<Unit> Sharp2()
  {
    return When(new Behavior<bool>(t => t.Value >= 1));
  }
  public static Event<Unit> When(Behavior<bool> fb)
  {
    return new Event<Unit>(() => Up(t => fb(t)));
  }
  public static IEnumerable<Tuple<Time, Unit>> Up(Func<Time, bool> e2)
  {
    foreach (var t in Time.Beat()) {
      if (e2(t)) {
        yield return Tuple.Create(t, new Unit());
      }
    }
  }
}


Where Time is a class and has Beat() static method for returning the instance at regular time intervals.

Saturday, February 12, 2011

Functional Reactive Programming(2)

I am studying Functional Reactive Programming(FRP).
I understand that FRP has 2 important concepts, they are Behavior and Event.
The behavior is function of time and it is continuous. The event is the list of pair of time and data and it is discrete.
I made a simple picture.

 

Sunday, February 6, 2011

Functional Reactive Programming

I am interested in Reactive Extensions.

It is based on the functional reactive programming(FRP) and I am studying FRP.

I am reading the pdf and the power point.

I think them useful but I do not understand them yet ...

Sunday, January 30, 2011

SQL99 grammar problem for the LL(k) parser.

When I define ANTLR SQL99 grammar, I encountered the problem that SQL grammar has rules that are mutually left-recursive.

For example, the boolean value expression is cyclic as following:

boolean value expression
-> boolean term
-> boolean factor
-> boolean test
-> boolean primary
-> predicate
-> comparison predicate
-> row value expression
-> row value special case
-> value expression
-> boolean value expression

So, I think that I define the value expression as the root,

value expression
-> boolean value expression
-> boolean term
-> boolean factor
-> boolean test
-> boolean primary
-> predicate
-> comparison predicate
-> row value expression
-> row value special case
-> (value expression is omitted)

and the place that boolean value expression is referenced by the other element of grammar is rewritten by the value expression.
Similarly, the row value expression is rewritten by the value expression, but I encountered a problem again.

The row value expression is refered by both comparison predicate and between predicate.
But I don't know the priority of the comparison and between predicates.

For instance, the following expression

A = B BETWEEN C AND D

is

(A = B) BETWEEN C AND D

or

A = (B BETWEEN C AND D)

?

First, I will define priority of the predicates in order of the grammar definition.

Sunday, January 23, 2011

Test data generation tool (3)

I thought using Irony .NET for analyzing SQL but I think using ANTLR now.
I experiment on analyzing SQL by ANTLR and I am making SQL99 grammar with reference to this site.
SQL is difficult ... .

Saturday, January 15, 2011

Test data generation tool (2)

I am making a tool that generates test data from a given SQL.
I think the architecture of the tool as the follow component diagram.

Saturday, January 8, 2011

Test data generation tool

I am making a tool which generates test data from SQLs.
The tool analyzes SQLs  and solves its WHERE clauses and the solution is used as the test data of the SQLs.

For example, think the following SQL
SELECT * FROM table1 WHERE table1.col1 >= 2

In WHERE clause, solve table1.col1 >= 2 and we get a solution table1.col1 = 2.
I think this data can be test data for the SQL.

I use Irony for analyzing SQLs and Z3 for solving the WHERE clauses of SQLs.

Saturday, January 1, 2011

Memo for developing web application

I write reminders for web application systems.

1. The session should contain only user information
 The server session contains only login  user information and http request parameters contains user id for operations and we have to check that the login user has the permission for the operations.

2. Separating links and buttons for the page transition
 Use link for the get method of http request and button for the post method of http request.

3. Method for long URI
 If we input words for the search conditions and the words are many, url is too long.
 It seems good for me to implement URI shortening service inside the system.