Skip to content

Commit

Permalink
Merge pull request #4 from vkamiansky/vi-introduce-modules
Browse files Browse the repository at this point in the history
Introduce base modules
  • Loading branch information
v-ilin authored Jul 6, 2017
2 parents e15a541 + 3cbef86 commit 9609e09
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 254 deletions.
Binary file removed code/FsComposite/.vs/FsComposite/v15/.suo
Binary file not shown.
41 changes: 41 additions & 0 deletions code/FsComposite/Composite.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Composite.Core.AssemblyInfo

open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices

// 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("Composite.Core")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("Composite.Core")>]
[<assembly: AssemblyCopyright("Copyright © 2017")>]
[<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
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("8163fd00-6eaa-48b8-93a5-ce10f35da2db")>]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]

do
()
83 changes: 83 additions & 0 deletions code/FsComposite/Composite.Core/Composite.Core.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>8163fd00-6eaa-48b8-93a5-ce10f35da2db</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Composite.Core</RootNamespace>
<AssemblyName>Composite.Core</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.1.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Composite.Core</Name>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Content Include="packages.config" />
<Compile Include="Composite.fs" />
<Compile Include="Processing.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ExtCore">
<HintPath>..\packages\ExtCore.0.8.46\lib\net45\ExtCore.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
<Name>FSharp.Core</Name>
<AssemblyName>FSharp.Core.dll</AssemblyName>
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace FsComposite
namespace Composite.Core

module CompositeToolset =

exception FatalError of string
module Composite =

type 'a Composite =
| Value of 'a
| Composite of LazyList<Composite<'a>>


exception FatalError of string

let l obj =
[obj] |> LazyList.ofList
[obj] |> LazyList.ofList

let toComposite obj =
match obj with
Expand All @@ -22,19 +21,18 @@ module CompositeToolset =
match obj with
| Composite x -> x
| x -> l x

let rec flat o =
match o with
| Composite x -> LazyList.collect flat x
| Value x -> l x

let rec ana scn obj =
match scn with
| [] -> obj
| f :: scn_tail -> match obj with
| Value x -> ana scn_tail (toComposite(f x))
| Composite x -> Composite(LazyList.map (ana scn) x)

let rec flat o =
match o with
| Composite x -> LazyList.collect flat x
| Value x -> l x

let cata scn obj =
match scn with
| [] -> LazyList.empty
Expand All @@ -46,13 +44,3 @@ module CompositeToolset =
| Nil -> raise(FatalError "Empty data sequence is an invalid binding result.")
| Cons(x, Nil) -> if x = obj then l x else [obj; x] |> LazyList.ofList
| x -> LazyList.cons obj x

// let flat obj =
// let rec flatInner o =
// match o with
// | Composite x -> LazyList.collect flatInner x
// | Value x -> l x
//
// match obj with
// | Value x -> obj
// | Composite x -> Composite (LazyList.map (fun y -> Composite(LazyList.map Value (flatInner y)) ) x)
25 changes: 25 additions & 0 deletions code/FsComposite/Composite.Core/Processing.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Composite.Core

open Composite.Core.Composite

module Processing =

let rec fold_2 acc f_update_acc lst =
match acc with
|(None, _) | (_, None) -> match lst with
| Nil -> acc
| Cons(h, tail) -> fold_2 (f_update_acc h acc) f_update_acc tail
| _ -> acc

let find_2_and_transform f_is_1 f_is_2 f_transform lst =
let f h t =
match f_is_1 h, f_is_2 h, t with
| _, true, (a, None) -> (a, Some h)
| true, _, (None, b) -> (Some h, b)
| _ -> t
match fold_2 (None, None) f lst with
| x -> f_transform x

let find_2_and_transform_strict f_is_1 f_is_2 f_transform lst =
let f_transform_strict = function | (Some x1, Some x2) -> l(f_transform (x1, x2)) | _ -> LazyList.empty
find_2_and_transform f_is_1 f_is_2 f_transform_strict lst
5 changes: 5 additions & 0 deletions code/FsComposite/Composite.Core/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExtCore" version="0.8.46" targetFramework="net452" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net452" />
</packages>
41 changes: 41 additions & 0 deletions code/FsComposite/Composite.Simple/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace FsComposite.Simple.AssemblyInfo

open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices

// 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("FsComposite.Simple")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("FsComposite.Simple")>]
[<assembly: AssemblyCopyright("Copyright © 2017")>]
[<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
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("d8aad155-ff6f-4957-82f7-dad5db8a606a")>]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]

do
()
84 changes: 84 additions & 0 deletions code/FsComposite/Composite.Simple/Composite.Simple.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>d8aad155-ff6f-4957-82f7-dad5db8a606a</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>FsComposite.Simple</RootNamespace>
<AssemblyName>Composite.Simple</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Composite.Simple</Name>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\FsComposite.Simple.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\FsComposite.Simple.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Data.fs" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="ExtCore">
<HintPath>..\packages\ExtCore.0.8.46\lib\net45\ExtCore.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Composite.Core\Composite.Core.fsproj">
<Name>Composite.Core</Name>
<Project>{8163fd00-6eaa-48b8-93a5-ce10f35da2db}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
32 changes: 32 additions & 0 deletions code/FsComposite/Composite.Simple/Data.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Composite.Simple

open Composite.Core.Composite
open Composite.Core.Processing

module Data =

type Simple =
| A
| B
| C

//how to expand

let expand obj =
match obj with
| A -> l B
| x -> l x

//how to fold

let transformAB obj =
let f1 = function | A -> true | _ -> false
let f2 = function | B -> true | _ -> false
let f = function | (Some a, Some b) -> l C | (None, Some b) -> l C | _ -> LazyList.empty
find_2_and_transform f1 f2 f obj

let transformABStrict obj =
let f1 = function | A -> true | _ -> false
let f2 = function | B -> true | _ -> false
let f = fun (a, b) -> C
find_2_and_transform_strict f1 f2 f obj
4 changes: 4 additions & 0 deletions code/FsComposite/Composite.Simple/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExtCore" version="0.8.46" targetFramework="net47" />
</packages>
File renamed without changes.
Loading

0 comments on commit 9609e09

Please sign in to comment.