From 39f45596d202a201e774225c151b89aa578d2d35 Mon Sep 17 00:00:00 2001 From: Paul Louth Date: Thu, 20 Nov 2014 01:05:29 +0000 Subject: [PATCH 1/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a29cea4..a975f94 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ A C# library of monads and a full set of parser combinators based on the Haskell The library is stable, functional and pretty well tested. +__NuGet__ https://www.nuget.org/packages/csharp-monad/ ### A note about laziness From fe0382d0e01b08bff7ca88842a657c1249a5c2b2 Mon Sep 17 00:00:00 2001 From: Paul Louth Date: Thu, 20 Nov 2014 18:19:59 +0000 Subject: [PATCH 2/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a975f94..fbc3934 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![csharp-monad](http://www.4four.org/images/csharp-monad-logo.png) + csharp-monad ============ From 5983fdd73435f04013480022fdc8e23f6b527cbf Mon Sep 17 00:00:00 2001 From: Aaron Brodersen Date: Fri, 13 Feb 2015 14:46:02 -0600 Subject: [PATCH 3/3] Fix line endings. --- .../src/ReaderWriterStateTests.cs | 160 +++++++++--------- CSharpMonad.UnitTests/src/WriterTests.cs | 144 ++++++++-------- 2 files changed, 152 insertions(+), 152 deletions(-) diff --git a/CSharpMonad.UnitTests/src/ReaderWriterStateTests.cs b/CSharpMonad.UnitTests/src/ReaderWriterStateTests.cs index 1f21b23..9967c96 100644 --- a/CSharpMonad.UnitTests/src/ReaderWriterStateTests.cs +++ b/CSharpMonad.UnitTests/src/ReaderWriterStateTests.cs @@ -1,80 +1,80 @@ -//////////////////////////////////////////////////////////////////////////////////////// -// The MIT License (MIT) -// -// Copyright (c) 2014 Paul Louth -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NUnit.Framework; -using Monad; - -namespace Monad.UnitTests -{ - [TestFixture] - public class ReaderWriterStateTests - { - [Test] - public void ReaderWriterStateTest1() - { - var world = RWS.Return(0); - - var rws = (from _ in world - from app in RWS.Get() - from env in RWS.Ask() - from x in Value(app.UsersLoggedIn, "Users logged in: " + app.UsersLoggedIn) - from y in Value(100, "System folder: " + env.SystemFolder) - from s in RWS.Put(new App { UsersLoggedIn = 35 }) - from t in RWS.Tell("Process complete") - select x * y) - .Memo(new Env(), new App()); - - var res = rws(); - - Assert.IsTrue(res.Value == 3400); - Assert.IsTrue(res.State.UsersLoggedIn == 35); - Assert.IsTrue(res.Output.Count() == 3); - Assert.IsTrue(res.Output.First() == "Users logged in: 34"); - Assert.IsTrue(res.Output.Skip(1).First() == "System folder: C:/Temp"); - Assert.IsTrue(res.Output.Skip(2).First() == "Process complete"); - } - - public static RWS Value(int val, string log) - { - return (Env r, App s) => RWS.Tell(val, log); - } - } - - - public class App - { - public int UsersLoggedIn = 34; - } - - public class Env - { - public string SystemFolder = "C:/Temp"; - } -} - +//////////////////////////////////////////////////////////////////////////////////////// +// The MIT License (MIT) +// +// Copyright (c) 2014 Paul Louth +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Monad; + +namespace Monad.UnitTests +{ + [TestFixture] + public class ReaderWriterStateTests + { + [Test] + public void ReaderWriterStateTest1() + { + var world = RWS.Return(0); + + var rws = (from _ in world + from app in RWS.Get() + from env in RWS.Ask() + from x in Value(app.UsersLoggedIn, "Users logged in: " + app.UsersLoggedIn) + from y in Value(100, "System folder: " + env.SystemFolder) + from s in RWS.Put(new App { UsersLoggedIn = 35 }) + from t in RWS.Tell("Process complete") + select x * y) + .Memo(new Env(), new App()); + + var res = rws(); + + Assert.IsTrue(res.Value == 3400); + Assert.IsTrue(res.State.UsersLoggedIn == 35); + Assert.IsTrue(res.Output.Count() == 3); + Assert.IsTrue(res.Output.First() == "Users logged in: 34"); + Assert.IsTrue(res.Output.Skip(1).First() == "System folder: C:/Temp"); + Assert.IsTrue(res.Output.Skip(2).First() == "Process complete"); + } + + public static RWS Value(int val, string log) + { + return (Env r, App s) => RWS.Tell(val, log); + } + } + + + public class App + { + public int UsersLoggedIn = 34; + } + + public class Env + { + public string SystemFolder = "C:/Temp"; + } +} + diff --git a/CSharpMonad.UnitTests/src/WriterTests.cs b/CSharpMonad.UnitTests/src/WriterTests.cs index 9a88d8c..cb9cf66 100644 --- a/CSharpMonad.UnitTests/src/WriterTests.cs +++ b/CSharpMonad.UnitTests/src/WriterTests.cs @@ -1,72 +1,72 @@ -//////////////////////////////////////////////////////////////////////////////////////// -// The MIT License (MIT) -// -// Copyright (c) 2014 Paul Louth -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -using System; -using System.Linq; -using NUnit.Framework; -using Monad.Utility; -using Monad; - -namespace Monad.UnitTests -{ - [TestFixture] - public class WriterTests - { - [Test] - public void Binding1() - { - var res = from a in LogNumber(3) - from b in LogNumber(5) - select a * b; - - var memo = res.Memo(); - - Assert.IsTrue(memo().Value == 15 && memo().Output.Count() == 2); - Assert.IsTrue(memo().Output.First() == "Got number: 3"); - Assert.IsTrue(memo().Output.Skip(1).First() == "Got number: 5"); - } - - [Test] - public void Binding2() - { - var res = from a in LogNumber(3) - from b in LogNumber(5) - from _ in Writer.Tell("Gonna multiply these two") - select a * b; - - var memo = res.Memo(); - - Assert.IsTrue(memo().Value == 15 && memo().Output.Count() == 3); - Assert.IsTrue(memo().Output.First() == "Got number: 3"); - Assert.IsTrue(memo().Output.Skip(1).First() == "Got number: 5"); - Assert.IsTrue(memo().Output.Skip(2).First() == "Gonna multiply these two"); - } - - private static Writer LogNumber(int num) - { - return () => Writer.Tell(num, "Got number: " + num); - } - } -} - +//////////////////////////////////////////////////////////////////////////////////////// +// The MIT License (MIT) +// +// Copyright (c) 2014 Paul Louth +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +using System; +using System.Linq; +using NUnit.Framework; +using Monad.Utility; +using Monad; + +namespace Monad.UnitTests +{ + [TestFixture] + public class WriterTests + { + [Test] + public void Binding1() + { + var res = from a in LogNumber(3) + from b in LogNumber(5) + select a * b; + + var memo = res.Memo(); + + Assert.IsTrue(memo().Value == 15 && memo().Output.Count() == 2); + Assert.IsTrue(memo().Output.First() == "Got number: 3"); + Assert.IsTrue(memo().Output.Skip(1).First() == "Got number: 5"); + } + + [Test] + public void Binding2() + { + var res = from a in LogNumber(3) + from b in LogNumber(5) + from _ in Writer.Tell("Gonna multiply these two") + select a * b; + + var memo = res.Memo(); + + Assert.IsTrue(memo().Value == 15 && memo().Output.Count() == 3); + Assert.IsTrue(memo().Output.First() == "Got number: 3"); + Assert.IsTrue(memo().Output.Skip(1).First() == "Got number: 5"); + Assert.IsTrue(memo().Output.Skip(2).First() == "Gonna multiply these two"); + } + + private static Writer LogNumber(int num) + { + return () => Writer.Tell(num, "Got number: " + num); + } + } +} +