├── .gitattributes
├── .gitignore
├── .nuget
└── packages.config
├── CSharpMonad.UnitTests
├── CSharpMonad.UnitTests.csproj
├── Properties
│ └── AssemblyInfo.cs
├── packages.config
└── src
│ ├── Combined.cs
│ ├── EitherTests.cs
│ ├── ErrorUnitTests.cs
│ ├── ExprParsers.cs
│ ├── IOTests.cs
│ ├── ImmutableListTests.cs
│ ├── LangTests.cs
│ ├── MLTests.cs
│ ├── MemoizationTests.cs
│ ├── OptionTests.cs
│ ├── ParsecTests.cs
│ ├── ReaderTests.cs
│ ├── ReaderWriterStateTests.cs
│ ├── StateTests.cs
│ ├── TryTests.cs
│ ├── WriterTests.cs
│ └── lex
│ ├── LexerTests.cs
│ └── TokTests.cs
├── CSharpMonad.sln
├── CSharpMonad
├── CSharpMonad.csproj
├── CSharpMonad.sln
├── CSharpMonad.xproj
├── Properties
│ └── AssemblyInfo.cs
├── lib
│ └── Monad.dll
├── project.json
├── project.lock.json
└── src
│ ├── EitherLazy.cs
│ ├── EitherStrict.cs
│ ├── IAppendable.cs
│ ├── IO.cs
│ ├── RWS.cs
│ ├── Reader.cs
│ ├── State.cs
│ ├── Try.cs
│ ├── Writer.cs
│ ├── ext
│ ├── EnumerableExt.cs
│ ├── ImmutableListExt.cs
│ ├── LiftExt.cs
│ ├── ObjectExt.cs
│ └── TupleExt.cs
│ ├── option-lazy
│ ├── Just.cs
│ ├── Nothing.cs
│ └── Option.cs
│ ├── option-strict
│ ├── Just.cs
│ ├── Nothing.cs
│ └── OptionStrict.cs
│ ├── parsec
│ ├── Empty.cs
│ ├── Parser.cs
│ ├── ParserChar.cs
│ ├── ParserError.cs
│ ├── ParserException.cs
│ ├── ParserExt.cs
│ ├── ParserResult.cs
│ ├── Parsers.cs
│ ├── Prim.cs
│ ├── SrcLoc.cs
│ ├── Tok.cs
│ ├── expr
│ │ ├── Assoc.cs
│ │ ├── ExprParser.cs
│ │ ├── Operator.cs
│ │ └── OperatorTable.cs
│ ├── language
│ │ ├── EmptyDef.cs
│ │ ├── Haskell98Def.cs
│ │ ├── HaskellDef.cs
│ │ ├── HaskellStyle.cs
│ │ └── JavaStyle.cs
│ └── token
│ │ ├── LanguageDef.cs
│ │ ├── TokenParser.cs
│ │ ├── TokenParsers.cs
│ │ ├── TokenTypes.cs
│ │ ├── bracketing
│ │ └── Bracketing.cs
│ │ ├── chars
│ │ └── Chars.cs
│ │ ├── idents
│ │ └── Idents.cs
│ │ ├── numbers
│ │ └── Numbers.cs
│ │ ├── ops
│ │ └── Ops.cs
│ │ └── strings
│ │ └── Strings.cs
│ └── utility
│ ├── ImmutableList.cs
│ ├── Lam.da.cs
│ ├── Memoize.cs
│ └── Unit.cs
├── LICENSE.md
├── README.md
└── csharp-monad.1.0.1.nuspec
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
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 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | .nuget
19 | packages/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 |
98 | # NuGet Packages Directory
99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100 | #packages/
101 |
102 | # Windows Azure Build Output
103 | csx
104 | *.build.csdef
105 |
106 | # Windows Store app package directory
107 | AppPackages/
108 |
109 | # Others
110 | sql/
111 | *.Cache
112 | ClientBin/
113 | [Ss]tyle[Cc]op.*
114 | ~$*
115 | *~
116 | *.dbmdl
117 | *.[Pp]ublish.xml
118 | *.pfx
119 | *.publishsettings
120 |
121 | # RIA/Silverlight projects
122 | Generated_Code/
123 |
124 | # Backup & report files from converting an old project file to a newer
125 | # Visual Studio version. Backup files are not needed, because we have git ;-)
126 | _UpgradeReport_Files/
127 | Backup*/
128 | UpgradeLog*.XML
129 | UpgradeLog*.htm
130 |
131 | # SQL Server files
132 | App_Data/*.mdf
133 | App_Data/*.ldf
134 |
135 |
136 | #LightSwitch generated files
137 | GeneratedArtifacts/
138 | _Pvt_Extensions/
139 | ModelManifest.xml
140 |
141 | # =========================
142 | # Windows detritus
143 | # =========================
144 |
145 | # Windows image file caches
146 | Thumbs.db
147 | ehthumbs.db
148 |
149 | # Folder config file
150 | Desktop.ini
151 |
152 | # Recycle Bin used on file shares
153 | $RECYCLE.BIN/
154 |
155 | # Mac desktop service store files
156 | .DS_Store
157 | /.vs/config/applicationhost.config
158 | /CSharpMonad/.vs/restore.dg
159 | *.lock.json
160 | /CSharpMonad/.vs/config/applicationhost.config
161 |
--------------------------------------------------------------------------------
/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CSharpMonad.UnitTests/CSharpMonad.UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 | {496943F4-17B4-41CB-8013-5499543E3DA0}
10 | Library
11 | Properties
12 | CSharpMonad.UnitTests
13 | CSharpMonad.UnitTests
14 | v4.5
15 | 512
16 | 12.0.0
17 | 2.0
18 | 0a724ffb
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | ..\packages\xunit.abstractions.2.0.0-rc1-build2826\lib\net35\xunit.abstractions.dll
47 |
48 |
49 | ..\packages\xunit.assert.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll
50 |
51 |
52 | ..\packages\xunit.extensibility.core.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | {254abd61-bedb-4478-9708-606e85310fe0}
85 | CSharpMonad
86 |
87 |
88 |
89 |
90 |
91 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
108 |
--------------------------------------------------------------------------------
/CSharpMonad.UnitTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Monad.UnitTests")]
9 | [assembly: AssemblyDescription("Monad library unit tests")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Monad.UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © Paul Louth 2014 - MIT License")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("64b47c63-9311-4431-bd6f-dbc8965bac9e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CSharpMonad.UnitTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/CSharpMonad.UnitTests/src/Combined.cs:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////////////////////////////////
2 | // The MIT License (MIT)
3 | //
4 | // Copyright (c) 2014 Paul Louth
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in all
14 | // copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | // SOFTWARE.
23 | //
24 |
25 | using System;
26 | using System.Linq;
27 |
28 | using Monad;
29 | using Xunit;
30 | using System.Reflection;
31 |
32 | namespace Monad.UnitTests
33 | {
34 | public class Combined
35 | {
36 | [Fact]
37 | public void Combined1()
38 | {
39 | var t1 = ErrIO(() => 1);
40 | var t2 = ErrIO(() => 2);
41 | var t3 = ErrIO(() => 3);
42 |
43 | var res = from one in t1
44 | from two in t2
45 | from thr in t3
46 | select one + two + thr;
47 |
48 | Assert.True(res().Value == 6);
49 | }
50 |
51 | [Fact]
52 | public void Combined2()
53 | {
54 |
55 | var t1 = ErrIO(() => 1);
56 | var t2 = ErrIO(() => 2);
57 | var t3 = ErrIO(() => 3);
58 | var fail = ErrIO(() =>
59 | {
60 | throw new Exception("Error");
61 | });
62 |
63 | var res = from one in t1
64 | from two in t2
65 | from thr in t3
66 | from err in fail
67 | select one + two + thr + err;
68 |
69 | Assert.True(res().IsFaulted);
70 | }
71 |
72 | private Try ErrIO(IO fn)
73 | {
74 | return new Try(() => fn());
75 | }
76 |
77 | private Try> Trans(IO inner)
78 | {
79 | return () => inner;
80 | }
81 |
82 | private Reader> Trans(Try inner)
83 | {
84 | return (env) => inner;
85 | }
86 |
87 | public IO Hello()
88 | {
89 | return () => "Hello,";
90 | }
91 |
92 | public IO World()
93 | {
94 | return () => " World";
95 | }
96 |
97 | // Messing
98 | [Fact]
99 | public void TransTest()
100 | {
101 | var errT = Trans(from h in Hello()
102 | from w in World()
103 | select h + w);
104 |
105 | var rdrT = Trans>(errT);
106 |
107 | Assert.True(rdrT("environ")().Value() == "Hello, World");
108 | }
109 |
110 | public Try