Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions FSharpTutorials/Kombinaattorit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//Sulutus ei ole pakollista:
let f(x,y) = x+y
let g x y = x+y

//Funktion tyyppi:
let I x = x
// x: a
Expand Down Expand Up @@ -37,15 +37,15 @@ let moi = vakioMoi 123
//function composition
let yhdistä1 f g x = g(f x)
let yhdistä2 f g x = (f >> g) x

//val yhdistä1 : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
//val yhdistä2 : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c


let yhdistä3 f g = (f >> g)


//käytännön esimerkki:
//let käsittele = (tallenna >> validoi >> lähetä)


Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CSharpExamples")]
Expand All @@ -14,8 +14,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

Expand All @@ -25,11 +25,11 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion FunctionalTutorial/CSharpExamples/PresisDemo/Script.fsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is a script that can be executed with the F# Interactive.
// This file is a script that can be executed with the F# Interactive.
// It can be used to explore and test the library project.
// Note that script files will not be part of the project build.

Expand Down
4 changes: 2 additions & 2 deletions FunctionalTutorial/CSharpExamples/PresisDemo/SlideDemo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

open System;

type PresentationKeeper(name: string, employer : string) =
type PresentationKeeper(name: string, employer : string) =
member lollis.name = name
member fuulis.employer = employer
override this.ToString() = name + ", " + employer
Expand All @@ -18,7 +18,7 @@ let topics = [ (2, "Functional programming from c# perspective, Linq principles"

let formatTopic topic keeper = String.Format ("{0} ({1})", topic, keeper.ToString())

let pimpTheList = topics |> Seq.sortBy (fun (prio,_,_) -> prio)
let pimpTheList = topics |> Seq.sortBy (fun (prio,_,_) -> prio)
|> Seq.map (fun (_, a, b) -> a,b)
|> Seq.map (fun x -> (formatTopic (fst x) (snd x)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UnitTests")]
Expand All @@ -14,8 +14,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

Expand All @@ -25,11 +25,11 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
14 changes: 7 additions & 7 deletions LegacyCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private List<List<string>> Decompose(string data)
{
char mark = '\n';
char mark2 = ',';

List<List<string>> result = new List<List<string>>();

foreach (string datedata in data.Split(mark))
Expand All @@ -51,21 +51,21 @@ private List<List<string>> Decompose(string data)

private List<Tuple<DateTime, double>> ReFormat(List<List<string>> list)
{

list.RemoveAt(0);

List<Tuple<DateTime, double>> result = new List<Tuple<DateTime,double>>();

foreach(var sublist in list){

string date = sublist[0];
string rate = sublist[4];

DateTime parseDate = DateTime.ParseExact(date, "yyyy-mm-dd", CultureInfo.InvariantCulture);
double parseRate = Double.Parse(rate, CultureInfo.GetCultureInfo("en-US"));

result.Add(new Tuple<DateTime, double>(parseDate, parseRate));

}

return result;
Expand Down
4 changes: 2 additions & 2 deletions NewCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ private IEnumerable<IEnumerable<string>> Decompose(string data)
private IEnumerable<Tuple<DateTime, double>> ReFormat(IEnumerable<IEnumerable<string>> list)
{

Func<string, DateTime> parseDate =
Func<string, DateTime> parseDate =
dt => DateTime.ParseExact(dt, "yyyy-mm-dd", CultureInfo.InvariantCulture);

Func<string, double> parseRate = rt => Double.Parse(rt, CultureInfo.GetCultureInfo("en-US"));

var result = from sublist in list.Skip(1)
select new Tuple<DateTime, double>
(parseDate(sublist.ElementAt(0)), parseRate(sublist.ElementAt(4)));

return result;
}

Expand Down
12 changes: 6 additions & 6 deletions Stocks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ open System.Collections.Generic
open System.Globalization
open System.IO
open System.Net
let public MakeUrl symbol (dfrom:DateTime) (dto:DateTime) =
let public MakeUrl symbol (dfrom:DateTime) (dto:DateTime) =
new Uri("http://ichart.finance.yahoo.com/table.csv?s=" + symbol +
"&e=" + dto.Day.ToString() + "&d=" + dto.Month.ToString() + "&f=" + dto.Year.ToString() +
"&g=d&b=" + dfrom.Day.ToString() + "&a=" + dfrom.Month.ToString() + "&c=" + dfrom.Year.ToString() +
"&ignore=.csv")

let internal fetch (url : Uri) =
let internal fetch (url : Uri) =
let req = WebRequest.Create (url) :?> HttpWebRequest
use stream = req.GetResponse().GetResponseStream()
use reader = new StreamReader(stream)
reader.ReadToEnd()

let internal decompose (response:string) =
let internal decompose (response:string) =
let split (mark:char) (data:string) =
data.Split(mark) |> Array.toList
response |> split '\n'
|> List.filter (fun f -> f<>"")
|> List.map (split ',')
|> List.map (split ',')


let internal reformat (sel) =
let parseDate d = DateTime.ParseExact(d, "yyyy-mm-dd", CultureInfo.InvariantCulture)
let parseRate r = Double.Parse(r, CultureInfo.GetCultureInfo("en-US"))
let focus (l:string list) =
let focus (l:string list) =
(parseDate l.[0], parseRate l.[4])
Seq.skip 1 sel |> Seq.map focus

let public GetResult url = (fetch >> decompose >> reformat) url

let DateMaxClose list = Seq.maxBy snd list

//let req = MakeUrl "MSFT" (new DateTime(2010, 2, 20)) (new DateTime(2010, 3, 25))
//let req = MakeUrl "MSFT" (new DateTime(2010, 2, 20)) (new DateTime(2010, 3, 25))
//let AvgClose = (GetResult >> Seq.map snd >> Seq.average) req
4 changes: 2 additions & 2 deletions StocksApplication/README
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

This is technical demo to apply F-Sharp (F#) language in real world application.
This is technical demo to apply F-Sharp (F#) language in real world application.
This application is close to real world enterprise application (with very optimal solutions, at least in 2011).

The function of this application is to get Stock Quote Data and Historical Stock Prices from Yahoo Finance


Architecture visaul presentation: Architecture.pptx

There are two web user interfaces:
There are two web user interfaces:
1. Silverlight 5.0 MVVM made with Expression Blend
- Silverlight F# 2.0 ViewModel and client logics dll
2. HTML 5.0 + jQuery 1.6.1 + Javascript (Ajax)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StocksApplication.Web")]
Expand All @@ -15,8 +15,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

Expand All @@ -26,11 +26,11 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}

var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;

Expand All @@ -44,7 +44,7 @@
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}

var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;

Expand All @@ -43,7 +43,7 @@
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class StocksService

var uri = Stocks.MakeUrl(quote, fromdate, todate);

try {
try {
return Stocks.GetResult(uri);
}catch(System.Net.WebException){
//throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ type StocksService =
//failwith("GetResult returned error");
let tmp = { Date = todate; Rate = -1.0 }
List.toSeq [tmp]

// example: http://localhost:49624/StocksService.svc/Symbol/MSFT/20100905/20100910

8 changes: 4 additions & 4 deletions StocksApplication/StocksApplication.Web/htmlclient/scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$(document).ready(function()
$(document).ready(function()
{
//Debug:
function concatObject(obj) {
Expand All @@ -12,18 +12,18 @@ $(document).ready(function()


Date.prototype.formatDDMMYYYYPlus = function(){
return this.getDate() + "." + (this.getMonth()+1) + "." + this.getFullYear();
return this.getDate() + "." + (this.getMonth()+1) + "." + this.getFullYear();
}
Date.prototype.formatDDMMYYYYMinus = function(){
return this.getDate() + "." + (this.getMonth()-1) + "." + this.getFullYear();
return this.getDate() + "." + (this.getMonth()-1) + "." + this.getFullYear();
}

function toyyyymmdd(str){
nums = str.split('.');
function prezero(num){
if(num.length<2)return "0"+num;
else return num;
}
}
return nums[2] + prezero(nums[1]) + prezero(nums[0]);
};

Expand Down
6 changes: 3 additions & 3 deletions StocksApplication/StocksApplicationSL/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ private void Application_Exit(object sender, EventArgs e)
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// If the app is running outside of the debugger then report the exception using
// the browser's exception mechanism. On IE this will display as a yellow alert
// the browser's exception mechanism. On IE this will display as a yellow alert
// icon in the status bar and Firefox will display a script error.
if (!System.Diagnostics.Debugger.IsAttached)
{

// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
Expand Down
2 changes: 1 addition & 1 deletion StocksApplication/StocksApplicationSL/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</ei:ChangePropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<sdk:DataGrid x:Name="Lista"
<sdk:DataGrid x:Name="Lista"
ItemsSource="{Binding Rates}" Height="208" Width="466" HorizontalAlignment="Left" VerticalAlignment="Top" AutoGenerateColumns="False">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Date" Binding="{Binding Date, StringFormat='dd.MM.yyyy'}"/>
Expand Down
Loading