Thursday, November 5, 2009

Simple App to learn/teach MACID

Lets say I launch a spice store. The old school brick and mortar type.

1. Add/modify customer info
2. Add/modify product info
3. Enter/ Modify Stock status
3. Enter/Modify Orders
4. generate EoD sales, stock reports etc
5. Generate news lettres

Lets start with this basic requirement and keep adding more as we get more business.
Eventually, I want an online store too. And a community for my customers to discuss recipes and other stuff.
========
Lets use this as a starting point.
http://www.kuliniewicz.org/blog/archives/2009/04/05/happstackstate-the-basics/

Saturday, February 2, 2008


import Control.Monad
import Data.Char
import Data.List
import System.Console.GetOpt
import System.Environment
import System.Exit
import System.IO
import Text.Printf


import System( getArgs )


main = do
args <- getArgs
-- print $ " The input args are :" ++ ( ( ((++ " ") . (show ) =<<) ) $ ( map read args ::[Int]) )
printf $ nqueens $ ( map read args ::[Int])!!0

qoer,noha,nova,nosea,noswa::(Integral n, Enum n ,Ord n)=> n -> [[n]] -- take size of board and return a list of clauses.

qoer n = [ [ (n* (j-1) + i ) | i <- [1..n] ] ++ [0] | j <- [1..n] ]
noha n = [ [ -1 *(n * ( j-1) + i ) , -1* (n * ( j-1) + k) , 0 ] | j <- [1..n] , i <- [ 1.. (n-1)] , k <- [ (i+1)..n] ]
nova n = [ [ -1 *(n * ( j-1) + i ) , -1*( n * ( k-1) + i) , 0 ] | i <- [1..n] , j <- [ 1.. (n-1)] , k <- [ (j+1)..n] ]
nosea n = [ [ -1 *(n * ( j-1) + i ) , -1*( n * ( j-1 + k ) + i + k ) , 0 ] | i <- [1..(n-1)] , j <- [ 1.. (n-1)] , k <- [1..(n*n)] , ( ( ( i+k) <= n ) && ( ( j+k) <=n ) ) ] -- bugs lurk here
noswa n = [ [ -1 *(n * ( j-1) + i ) , -1*( n * ( j-1 + k ) + i - k ) , 0 ] | i <- [2..n] , j <- [ 1.. (n-1)] , k <- [1..(n*n)] , ( ( ( i-k) >= 1 ) && ( ( j+k) <=n ) ) ] -- bugs lurk here

generate::(Integral n, Enum n, Ord n) => n -> [[n]] -- -- take size of board and return a list of clauses.
generate n = ( qoer n) ++ (noha n) ++ (nova n) ++ (nosea n) ++ (noswa n)

printclause::(Integral n, Enum n, Ord n) => [n]->String
printclause l = (((++" ").show) =<< ( init l)) ++ (show ( last l) )

nqueens::(Integral n, Enum n, Ord n) => n -> String
nqueens nq = (header nv nc ) ++ unlines ( map printclause clauses )
where
clauses = generate nq
nc = genericLength clauses
nv = nq *nq

header::(Integral n, Enum n, Ord n)=>n->n->String
header nv nc ="p cnf " ++ (show nv )++ " " ++ ( show nc )++ "\n"

Friday, January 18, 2008

HappS and HStringTemplate

I was able to follow the instructions on the Happs.org site and get a rudimentary static file only site up and running. To be able to run a wiki etc.. i need to do some more things..

1. Difficulty is that there is no good documentation at this point. So it is quite an uphill task to try and understand how it all works.

The plan is to write a 20 minute wiki tutorial for HappS , hopefully using ANTLR StringTemplate

Tuesday, July 24, 2007

Haskell types and classes

data -- corresponds most with keyword class in Cpp/Java
type -- typedef
newtype -- mixture of typedef, and data with some restrictions
class -- corresponds to interface
instance -- corresponds to implements
kind

Saturday, July 14, 2007

Sudoku Solver

This sudoku solver is my attempt at a clean architecture. I want to make sure to do the home work properly before coding. Basically once this solver is implemented, it should be idiomatic of solutions to a lot of other problems.

the sudoku solver should apply solver algorithms from a set until a test case is solved.
pseudo code:
A B C
mysudosol::( Set of algos) -> (Set of puzzles)->( Set of solved puzzles)

A can be a container of actions each of which takes a puzzle state , transforms it some how and returns the transformed version.

B can be a container of puzzles, even a list would do.
C same as B

as for the algos, personally i dont like having to implement an algo in one place, and then register it or add it to the set A explicity. it would be great if that could be discovered as opposed to having to register. eg: i implement mysooperdoopersolveralgo as an action that can be part of the set A, and put it in a certain place, and it autimatically gets included in A. now this wouldn't be that much to think about, if i wanted to put all the implementations in A directly, but i want them else where, and i suspect in the future i will get third party solvers too. in that case, i want to just put their solver in a place, and not have to recompile my sources. but i don't know yet how that works with Haskell