Skip to content

Commit 00dfe6c

Browse files
committed
Initial commit.
0 parents  commit 00dfe6c

17 files changed

+1032
-0
lines changed

.gitignore

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Xamarin Studio / monodevelop user-specific
10+
*.userprefs
11+
*.dll.mdb
12+
*.exe.mdb
13+
14+
# Build results
15+
16+
[Dd]ebug/
17+
[Rr]elease/
18+
x64/
19+
build/
20+
[Bb]in/
21+
[Oo]bj/
22+
23+
# MSTest test Results
24+
[Tt]est[Rr]esult*/
25+
[Bb]uild[Ll]og.*
26+
27+
*_i.c
28+
*_p.c
29+
*.ilk
30+
*.meta
31+
*.obj
32+
*.pch
33+
*.pdb
34+
*.pgc
35+
*.pgd
36+
*.rsp
37+
*.sbr
38+
*.tlb
39+
*.tli
40+
*.tlh
41+
*.tmp
42+
*.tmp_proj
43+
*.log
44+
*.vspscc
45+
*.vssscc
46+
.builds
47+
*.pidb
48+
*.log
49+
*.scc
50+
51+
# Visual C++ cache files
52+
ipch/
53+
*.aps
54+
*.ncb
55+
*.opensdf
56+
*.sdf
57+
*.cachefile
58+
59+
# Visual Studio profiler
60+
*.psess
61+
*.vsp
62+
*.vspx
63+
64+
# Other Visual Studio data
65+
.vs/
66+
67+
# Guidance Automation Toolkit
68+
*.gpState
69+
70+
# ReSharper is a .NET coding add-in
71+
_ReSharper*/
72+
*.[Rr]e[Ss]harper
73+
74+
# TeamCity is a build add-in
75+
_TeamCity*
76+
77+
# DotCover is a Code Coverage Tool
78+
*.dotCover
79+
80+
# NCrunch
81+
*.ncrunch*
82+
.*crunch*.local.xml
83+
84+
# Installshield output folder
85+
[Ee]xpress/
86+
87+
# DocProject is a documentation generator add-in
88+
DocProject/buildhelp/
89+
DocProject/Help/*.HxT
90+
DocProject/Help/*.HxC
91+
DocProject/Help/*.hhc
92+
DocProject/Help/*.hhk
93+
DocProject/Help/*.hhp
94+
DocProject/Help/Html2
95+
DocProject/Help/html
96+
97+
# Click-Once directory
98+
publish/
99+
100+
# Publish Web Output
101+
*.Publish.xml
102+
103+
# Enable nuget.exe in the .nuget folder (though normally executables are not tracked)
104+
!.nuget/NuGet.exe
105+
106+
# Windows Azure Build Output
107+
csx
108+
*.build.csdef
109+
110+
# Windows Store app package directory
111+
AppPackages/
112+
113+
# VSCode
114+
.vscode/
115+
116+
# Others
117+
sql/
118+
*.Cache
119+
ClientBin/
120+
[Ss]tyle[Cc]op.*
121+
~$*
122+
*~
123+
*.dbmdl
124+
*.[Pp]ublish.xml
125+
*.pfx
126+
*.publishsettings
127+
128+
# RIA/Silverlight projects
129+
Generated_Code/
130+
131+
# Backup & report files from converting an old project file to a newer
132+
# Visual Studio version. Backup files are not needed, because we have git ;-)
133+
_UpgradeReport_Files/
134+
Backup*/
135+
UpgradeLog*.XML
136+
UpgradeLog*.htm
137+
138+
# SQL Server files
139+
App_Data/*.mdf
140+
App_Data/*.ldf
141+
142+
143+
#LightSwitch generated files
144+
GeneratedArtifacts/
145+
_Pvt_Extensions/
146+
ModelManifest.xml
147+
148+
# =========================
149+
# Windows detritus
150+
# =========================
151+
152+
# Windows image file caches
153+
Thumbs.db
154+
ehthumbs.db
155+
156+
# Folder config file
157+
Desktop.ini
158+
159+
# Recycle Bin used on file shares
160+
$RECYCLE.BIN/
161+
162+
# Mac desktop service store files
163+
.DS_Store
164+
165+
# ===================================================
166+
# Exclude F# project specific directories and files
167+
# ===================================================
168+
169+
# NuGet Packages Directory
170+
packages/
171+
172+
# Generated documentation folder
173+
docs/output/
174+
175+
# Temp folder used for publishing docs
176+
temp/
177+
178+
# Test results produced by build
179+
TestResult.xml
180+
TestResults.xml
181+
182+
# Nuget outputs
183+
*.nupkg
184+
release.cmd
185+
release.sh
186+
localpackages/
187+
paket-files
188+
*.orig
189+
.paket/paket.exe
190+
docs/content/license.md
191+
docs/content/release-notes.md
192+
.fake
193+
docs/tools/FSharp.Formatting.svclog

CSharpMonadic.sln

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpMonadic", "CSharpMonadic\CSharpMonadic.csproj", "{B323B164-7616-480E-94E3-E61A96A5462A}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Option", "Option\Option.csproj", "{3113CE49-9790-452E-B9D9-9A5BA2A1D1D9}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C37AAB02-4798-4109-80A7-B58698190511}"
11+
ProjectSection(SolutionItems) = preProject
12+
LICENSE = LICENSE
13+
EndProjectSection
14+
EndProject
15+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpMonadic", "FSharpMonadic\FSharpMonadic.fsproj", "{B91B6EBD-2BCC-4333-BB03-51F6BEF6AB0D}"
16+
EndProject
17+
Global
18+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
19+
Debug|Any CPU = Debug|Any CPU
20+
Release|Any CPU = Release|Any CPU
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{B323B164-7616-480E-94E3-E61A96A5462A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{B323B164-7616-480E-94E3-E61A96A5462A}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{B323B164-7616-480E-94E3-E61A96A5462A}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{B323B164-7616-480E-94E3-E61A96A5462A}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{3113CE49-9790-452E-B9D9-9A5BA2A1D1D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{3113CE49-9790-452E-B9D9-9A5BA2A1D1D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{3113CE49-9790-452E-B9D9-9A5BA2A1D1D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{3113CE49-9790-452E-B9D9-9A5BA2A1D1D9}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{B91B6EBD-2BCC-4333-BB03-51F6BEF6AB0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{B91B6EBD-2BCC-4333-BB03-51F6BEF6AB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{B91B6EBD-2BCC-4333-BB03-51F6BEF6AB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{B91B6EBD-2BCC-4333-BB03-51F6BEF6AB0D}.Release|Any CPU.Build.0 = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(SolutionProperties) = preSolution
37+
HideSolutionNode = FALSE
38+
EndGlobalSection
39+
EndGlobal

CSharpMonadic/CSharpMonadic.csproj

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{B323B164-7616-480E-94E3-E61A96A5462A}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>CSharpMonadic</RootNamespace>
10+
<AssemblyName>CSharpMonadic</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
<PlatformTarget>AnyCPU</PlatformTarget>
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<PlatformTarget>AnyCPU</PlatformTarget>
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="Microsoft.CSharp" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<ProjectReference Include="..\Option\Option.csproj">
44+
<Project>{3113ce49-9790-452e-b9d9-9a5ba2a1d1d9}</Project>
45+
<Name>Option</Name>
46+
</ProjectReference>
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
</Project>

CSharpMonadic/Program.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// CSharpMonadic
4+
// Copyright (c) 2017 Kouji Matsui (@kekyo2)
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
/////////////////////////////////////////////////////////////////////////////////////////////////
19+
20+
using System;
21+
using System.Linq;
22+
23+
namespace CenterCLR
24+
{
25+
class Program
26+
{
27+
static void Main(string[] args)
28+
{
29+
////////////////////////////////////////////////////////////////////
30+
// Option (Maybe) monad implementations.
31+
32+
var option11 = Optional.Return(1);
33+
var option12 = option11.Bind(value1 =>
34+
{
35+
var option21 = Optional.Return(2);
36+
return option21.Bind(value2 =>
37+
{
38+
var option31 = Optional.Return(3);
39+
return option31.Bind(value3 => Optional.Return(value1 + value2 + value3));
40+
});
41+
});
42+
option12.Match(Console.WriteLine, () => { });
43+
44+
////////////////////////////////////////////////////////////////////
45+
// LINQ expressions maybe monadic?
46+
47+
var list11 = new[] {1};
48+
var list12 = list11.SelectMany(value1 =>
49+
{
50+
var list21 = new[] {2};
51+
return list21.SelectMany(value2 =>
52+
{
53+
var list31 = new[] {3};
54+
return list31.SelectMany(value3 => new[] {value1 + value2 + value3});
55+
});
56+
});
57+
foreach (var value in list12) Console.WriteLine(value);
58+
59+
////////////////////////////////////////////////////////////////////
60+
// Option monad acts by LINQ query expressions.
61+
62+
var optionResult =
63+
from value1 in Optional.Return(1)
64+
from value2 in Optional.Return(2)
65+
from value3 in Optional.Return(3)
66+
select value1 + value2 + value3;
67+
optionResult.Match(Console.WriteLine, () => { });
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)