mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-28 07:08:58 +00:00
Demonstrate that this is too dumb
This commit is contained in:
@@ -2,8 +2,8 @@ namespace ConsumePlugin
|
|||||||
|
|
||||||
open WoofWare.Myriad.Plugins
|
open WoofWare.Myriad.Plugins
|
||||||
|
|
||||||
type Const =
|
type Const<'a> =
|
||||||
| Int of int
|
| Verbatim of 'a
|
||||||
| String of string
|
| String of string
|
||||||
|
|
||||||
type PairOpKind =
|
type PairOpKind =
|
||||||
@@ -11,12 +11,12 @@ type PairOpKind =
|
|||||||
| ThenDoSeq
|
| ThenDoSeq
|
||||||
|
|
||||||
[<CreateCatamorphism "TreeCata">]
|
[<CreateCatamorphism "TreeCata">]
|
||||||
type Tree =
|
type Tree<'a> =
|
||||||
| Const of Const
|
| Const of Const<'a>
|
||||||
| Pair of Tree * Tree * PairOpKind
|
| Pair of Tree<'a> * Tree<'a> * PairOpKind
|
||||||
| Sequential of Tree list
|
| Sequential of Tree<'a> list
|
||||||
| Builder of Tree * TreeBuilder
|
| Builder of Tree<'a> * TreeBuilder<'a>
|
||||||
|
|
||||||
and TreeBuilder =
|
and TreeBuilder<'a> =
|
||||||
| Child of TreeBuilder
|
| Child of TreeBuilder<'a>
|
||||||
| Parent of Tree
|
| Parent of Tree<'a>
|
||||||
|
|||||||
@@ -47,6 +47,10 @@
|
|||||||
<Compile Include="GeneratedFileSystem.fs">
|
<Compile Include="GeneratedFileSystem.fs">
|
||||||
<MyriadFile>FSharpForFunAndProfitCata.fs</MyriadFile>
|
<MyriadFile>FSharpForFunAndProfitCata.fs</MyriadFile>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="List.fs" />
|
||||||
|
<Compile Include="ListCata.fs">
|
||||||
|
<MyriadFile>List.fs</MyriadFile>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -50,19 +50,3 @@ type Gift =
|
|||||||
| Wrapped of Gift * WrappingPaperStyle
|
| Wrapped of Gift * WrappingPaperStyle
|
||||||
| Boxed of Gift
|
| Boxed of Gift
|
||||||
| WithACard of Gift * message : string
|
| WithACard of Gift * message : string
|
||||||
|
|
||||||
[<CreateCatamorphism "MyListCata">]
|
|
||||||
type MyList<'a> =
|
|
||||||
| Nil
|
|
||||||
| Cons of ConsCase<'a>
|
|
||||||
|
|
||||||
and ConsCase<'a> =
|
|
||||||
{
|
|
||||||
Head : 'a
|
|
||||||
Tail : MyList<'a>
|
|
||||||
}
|
|
||||||
|
|
||||||
[<CreateCatamorphism "MyList2Cata">]
|
|
||||||
type MyList2<'a> =
|
|
||||||
| Nil
|
|
||||||
| Cons of 'a * MyList2<'a>
|
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ namespace ConsumePlugin
|
|||||||
open WoofWare.Myriad.Plugins
|
open WoofWare.Myriad.Plugins
|
||||||
|
|
||||||
/// Description of how to combine cases during a fold
|
/// Description of how to combine cases during a fold
|
||||||
type TreeBuilderCataCase<'TreeBuilder, 'Tree> =
|
type TreeBuilderCataCase<'a, 'TreeBuilder, 'Tree> =
|
||||||
/// How to operate on the Child case
|
/// How to operate on the Child case
|
||||||
abstract Child : 'TreeBuilder -> 'TreeBuilder
|
abstract Child : 'TreeBuilder -> 'TreeBuilder
|
||||||
/// How to operate on the Parent case
|
/// How to operate on the Parent case
|
||||||
abstract Parent : 'Tree -> 'TreeBuilder
|
abstract Parent : 'Tree -> 'TreeBuilder
|
||||||
|
|
||||||
/// Description of how to combine cases during a fold
|
/// Description of how to combine cases during a fold
|
||||||
type TreeCataCase<'TreeBuilder, 'Tree> =
|
type TreeCataCase<'a, 'TreeBuilder, 'Tree> =
|
||||||
/// How to operate on the Const case
|
/// How to operate on the Const case
|
||||||
abstract Const : Const -> 'Tree
|
abstract Const : Const -> 'Tree
|
||||||
/// How to operate on the Pair case
|
/// How to operate on the Pair case
|
||||||
@@ -30,28 +30,28 @@ type TreeCataCase<'TreeBuilder, 'Tree> =
|
|||||||
abstract Builder : 'Tree -> 'TreeBuilder -> 'Tree
|
abstract Builder : 'Tree -> 'TreeBuilder -> 'Tree
|
||||||
|
|
||||||
/// Specifies how to perform a fold (catamorphism) over the type Tree and its friends.
|
/// Specifies how to perform a fold (catamorphism) over the type Tree and its friends.
|
||||||
type TreeCata<'TreeBuilder, 'Tree> =
|
type TreeCata<'a, 'a, 'TreeBuilder, 'Tree> =
|
||||||
{
|
{
|
||||||
/// How to perform a fold (catamorphism) over the type TreeBuilder
|
/// How to perform a fold (catamorphism) over the type TreeBuilder
|
||||||
TreeBuilder : TreeBuilderCataCase<'TreeBuilder, 'Tree>
|
TreeBuilder : TreeBuilderCataCase<'a, 'TreeBuilder, 'Tree>
|
||||||
/// How to perform a fold (catamorphism) over the type Tree
|
/// How to perform a fold (catamorphism) over the type Tree
|
||||||
Tree : TreeCataCase<'TreeBuilder, 'Tree>
|
Tree : TreeCataCase<'a, 'TreeBuilder, 'Tree>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Methods to perform a catamorphism over the type Tree
|
/// Methods to perform a catamorphism over the type Tree
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module TreeCata =
|
module TreeCata =
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
type private Instruction =
|
type private Instruction<'a, 'a> =
|
||||||
| Process__TreeBuilder of TreeBuilder
|
| Process__TreeBuilder of TreeBuilder<'a>
|
||||||
| Process__Tree of Tree
|
| Process__Tree of Tree<'a>
|
||||||
| TreeBuilder_Child
|
| TreeBuilder_Child
|
||||||
| TreeBuilder_Parent
|
| TreeBuilder_Parent
|
||||||
| Tree_Pair of PairOpKind
|
| Tree_Pair of PairOpKind
|
||||||
| Tree_Sequential of int
|
| Tree_Sequential of int
|
||||||
| Tree_Builder
|
| Tree_Builder
|
||||||
|
|
||||||
let private loop (cata : TreeCata<_, _>) (instructions : ResizeArray<Instruction>) =
|
let private loop (cata : TreeCata<_, _, _, _>) (instructions : ResizeArray<Instruction<_, _>>) =
|
||||||
let treeStack = ResizeArray ()
|
let treeStack = ResizeArray ()
|
||||||
let treeBuilderStack = ResizeArray ()
|
let treeBuilderStack = ResizeArray ()
|
||||||
|
|
||||||
@@ -120,14 +120,18 @@ module TreeCata =
|
|||||||
treeBuilderStack, treeStack
|
treeBuilderStack, treeStack
|
||||||
|
|
||||||
/// Execute the catamorphism.
|
/// Execute the catamorphism.
|
||||||
let runTreeBuilder (cata : TreeCata<'TreeBuilderRet, 'TreeRet>) (x : TreeBuilder) : 'TreeBuilderRet =
|
let runTreeBuilder
|
||||||
|
(cata : TreeCata<'a, 'a, 'TreeBuilderRet, 'TreeRet>)
|
||||||
|
(x : TreeBuilder<'a, 'a>)
|
||||||
|
: 'TreeBuilderRet
|
||||||
|
=
|
||||||
let instructions = ResizeArray ()
|
let instructions = ResizeArray ()
|
||||||
instructions.Add (Instruction.Process__TreeBuilder x)
|
instructions.Add (Instruction.Process__TreeBuilder x)
|
||||||
let treeBuilderRetStack, treeRetStack = loop cata instructions
|
let treeBuilderRetStack, treeRetStack = loop cata instructions
|
||||||
Seq.exactlyOne treeBuilderRetStack
|
Seq.exactlyOne treeBuilderRetStack
|
||||||
|
|
||||||
/// Execute the catamorphism.
|
/// Execute the catamorphism.
|
||||||
let runTree (cata : TreeCata<'TreeBuilderRet, 'TreeRet>) (x : Tree) : 'TreeRet =
|
let runTree (cata : TreeCata<'a, 'a, 'TreeBuilderRet, 'TreeRet>) (x : Tree<'a, 'a>) : 'TreeRet =
|
||||||
let instructions = ResizeArray ()
|
let instructions = ResizeArray ()
|
||||||
instructions.Add (Instruction.Process__Tree x)
|
instructions.Add (Instruction.Process__Tree x)
|
||||||
let treeBuilderRetStack, treeRetStack = loop cata instructions
|
let treeBuilderRetStack, treeRetStack = loop cata instructions
|
||||||
|
|||||||
@@ -150,112 +150,3 @@ module GiftCata =
|
|||||||
instructions.Add (Instruction.Process__Gift x)
|
instructions.Add (Instruction.Process__Gift x)
|
||||||
let giftRetStack = loop cata instructions
|
let giftRetStack = loop cata instructions
|
||||||
Seq.exactlyOne giftRetStack
|
Seq.exactlyOne giftRetStack
|
||||||
namespace ConsumePlugin
|
|
||||||
|
|
||||||
open WoofWare.Myriad.Plugins
|
|
||||||
|
|
||||||
/// Description of how to combine cases during a fold
|
|
||||||
type MyListCataCase<'a, 'MyList> =
|
|
||||||
/// How to operate on the Nil case
|
|
||||||
abstract Nil : 'MyList
|
|
||||||
/// How to operate on the Cons case
|
|
||||||
abstract Cons : head : 'a -> tail : 'MyList -> 'MyList
|
|
||||||
|
|
||||||
/// Specifies how to perform a fold (catamorphism) over the type MyList and its friends.
|
|
||||||
type MyListCata<'a, 'MyList> =
|
|
||||||
{
|
|
||||||
/// How to perform a fold (catamorphism) over the type MyList
|
|
||||||
MyList : MyListCataCase<'a, 'MyList>
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Methods to perform a catamorphism over the type MyList
|
|
||||||
[<RequireQualifiedAccess>]
|
|
||||||
module MyListCata =
|
|
||||||
[<RequireQualifiedAccess>]
|
|
||||||
type private Instruction<'a> =
|
|
||||||
| Process__MyList of MyList<'a>
|
|
||||||
| MyList_Cons of 'a
|
|
||||||
|
|
||||||
let private loop (cata : MyListCata<_, _>) (instructions : ResizeArray<Instruction<_>>) =
|
|
||||||
let myListStack = ResizeArray ()
|
|
||||||
|
|
||||||
while instructions.Count > 0 do
|
|
||||||
let currentInstruction = instructions.[instructions.Count - 1]
|
|
||||||
instructions.RemoveAt (instructions.Count - 1)
|
|
||||||
|
|
||||||
match currentInstruction with
|
|
||||||
| Instruction.Process__MyList x ->
|
|
||||||
match x with
|
|
||||||
| MyList.Nil -> cata.MyList.Nil |> myListStack.Add
|
|
||||||
| MyList.Cons ({
|
|
||||||
Head = head
|
|
||||||
Tail = tail
|
|
||||||
}) ->
|
|
||||||
instructions.Add (Instruction.MyList_Cons (head))
|
|
||||||
instructions.Add (Instruction.Process__MyList tail)
|
|
||||||
| Instruction.MyList_Cons (head) ->
|
|
||||||
let tail = myListStack.[myListStack.Count - 1]
|
|
||||||
myListStack.RemoveAt (myListStack.Count - 1)
|
|
||||||
cata.MyList.Cons head tail |> myListStack.Add
|
|
||||||
|
|
||||||
myListStack
|
|
||||||
|
|
||||||
/// Execute the catamorphism.
|
|
||||||
let runMyList (cata : MyListCata<'a, 'MyListRet>) (x : MyList<'a>) : 'MyListRet =
|
|
||||||
let instructions = ResizeArray ()
|
|
||||||
instructions.Add (Instruction.Process__MyList x)
|
|
||||||
let myListRetStack = loop cata instructions
|
|
||||||
Seq.exactlyOne myListRetStack
|
|
||||||
namespace ConsumePlugin
|
|
||||||
|
|
||||||
open WoofWare.Myriad.Plugins
|
|
||||||
|
|
||||||
/// Description of how to combine cases during a fold
|
|
||||||
type MyList2CataCase<'a, 'MyList2> =
|
|
||||||
/// How to operate on the Nil case
|
|
||||||
abstract Nil : 'MyList2
|
|
||||||
/// How to operate on the Cons case
|
|
||||||
abstract Cons : 'a -> 'MyList2 -> 'MyList2
|
|
||||||
|
|
||||||
/// Specifies how to perform a fold (catamorphism) over the type MyList2 and its friends.
|
|
||||||
type MyList2Cata<'a, 'MyList2> =
|
|
||||||
{
|
|
||||||
/// How to perform a fold (catamorphism) over the type MyList2
|
|
||||||
MyList2 : MyList2CataCase<'a, 'MyList2>
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Methods to perform a catamorphism over the type MyList2
|
|
||||||
[<RequireQualifiedAccess>]
|
|
||||||
module MyList2Cata =
|
|
||||||
[<RequireQualifiedAccess>]
|
|
||||||
type private Instruction<'a> =
|
|
||||||
| Process__MyList2 of MyList2<'a>
|
|
||||||
| MyList2_Cons of 'a
|
|
||||||
|
|
||||||
let private loop (cata : MyList2Cata<_, _>) (instructions : ResizeArray<Instruction<_>>) =
|
|
||||||
let myList2Stack = ResizeArray ()
|
|
||||||
|
|
||||||
while instructions.Count > 0 do
|
|
||||||
let currentInstruction = instructions.[instructions.Count - 1]
|
|
||||||
instructions.RemoveAt (instructions.Count - 1)
|
|
||||||
|
|
||||||
match currentInstruction with
|
|
||||||
| Instruction.Process__MyList2 x ->
|
|
||||||
match x with
|
|
||||||
| MyList2.Nil -> cata.MyList2.Nil |> myList2Stack.Add
|
|
||||||
| MyList2.Cons (arg0_0, arg1_0) ->
|
|
||||||
instructions.Add (Instruction.MyList2_Cons (arg0_0))
|
|
||||||
instructions.Add (Instruction.Process__MyList2 arg1_0)
|
|
||||||
| Instruction.MyList2_Cons (arg0_0) ->
|
|
||||||
let arg1_0 = myList2Stack.[myList2Stack.Count - 1]
|
|
||||||
myList2Stack.RemoveAt (myList2Stack.Count - 1)
|
|
||||||
cata.MyList2.Cons arg0_0 arg1_0 |> myList2Stack.Add
|
|
||||||
|
|
||||||
myList2Stack
|
|
||||||
|
|
||||||
/// Execute the catamorphism.
|
|
||||||
let runMyList2 (cata : MyList2Cata<'a, 'MyList2Ret>) (x : MyList2<'a>) : 'MyList2Ret =
|
|
||||||
let instructions = ResizeArray ()
|
|
||||||
instructions.Add (Instruction.Process__MyList2 x)
|
|
||||||
let myList2RetStack = loop cata instructions
|
|
||||||
Seq.exactlyOne myList2RetStack
|
|
||||||
|
|||||||
19
ConsumePlugin/List.fs
Normal file
19
ConsumePlugin/List.fs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace ConsumePlugin
|
||||||
|
|
||||||
|
open WoofWare.Myriad.Plugins
|
||||||
|
|
||||||
|
[<CreateCatamorphism "MyListCata">]
|
||||||
|
type MyList<'a> =
|
||||||
|
| Nil
|
||||||
|
| Cons of ConsCase<'a>
|
||||||
|
|
||||||
|
and ConsCase<'a> =
|
||||||
|
{
|
||||||
|
Head : 'a
|
||||||
|
Tail : MyList<'a>
|
||||||
|
}
|
||||||
|
|
||||||
|
[<CreateCatamorphism "MyList2Cata">]
|
||||||
|
type MyList2<'a> =
|
||||||
|
| Nil
|
||||||
|
| Cons of 'a * MyList2<'a>
|
||||||
118
ConsumePlugin/ListCata.fs
Normal file
118
ConsumePlugin/ListCata.fs
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// This code was generated by myriad.
|
||||||
|
// Changes to this file will be lost when the code is regenerated.
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace ConsumePlugin
|
||||||
|
|
||||||
|
open WoofWare.Myriad.Plugins
|
||||||
|
|
||||||
|
/// Description of how to combine cases during a fold
|
||||||
|
type MyListCataCase<'a, 'MyList> =
|
||||||
|
/// How to operate on the Nil case
|
||||||
|
abstract Nil : 'MyList
|
||||||
|
/// How to operate on the Cons case
|
||||||
|
abstract Cons : head : 'a -> tail : 'MyList -> 'MyList
|
||||||
|
|
||||||
|
/// Specifies how to perform a fold (catamorphism) over the type MyList and its friends.
|
||||||
|
type MyListCata<'a, 'MyList> =
|
||||||
|
{
|
||||||
|
/// How to perform a fold (catamorphism) over the type MyList
|
||||||
|
MyList : MyListCataCase<'a, 'MyList>
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Methods to perform a catamorphism over the type MyList
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module MyListCata =
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
type private Instruction<'a> =
|
||||||
|
| Process__MyList of MyList<'a>
|
||||||
|
| MyList_Cons of 'a
|
||||||
|
|
||||||
|
let private loop (cata : MyListCata<_, _>) (instructions : ResizeArray<Instruction<_>>) =
|
||||||
|
let myListStack = ResizeArray ()
|
||||||
|
|
||||||
|
while instructions.Count > 0 do
|
||||||
|
let currentInstruction = instructions.[instructions.Count - 1]
|
||||||
|
instructions.RemoveAt (instructions.Count - 1)
|
||||||
|
|
||||||
|
match currentInstruction with
|
||||||
|
| Instruction.Process__MyList x ->
|
||||||
|
match x with
|
||||||
|
| MyList.Nil -> cata.MyList.Nil |> myListStack.Add
|
||||||
|
| MyList.Cons ({
|
||||||
|
Head = head
|
||||||
|
Tail = tail
|
||||||
|
}) ->
|
||||||
|
instructions.Add (Instruction.MyList_Cons (head))
|
||||||
|
instructions.Add (Instruction.Process__MyList tail)
|
||||||
|
| Instruction.MyList_Cons (head) ->
|
||||||
|
let tail = myListStack.[myListStack.Count - 1]
|
||||||
|
myListStack.RemoveAt (myListStack.Count - 1)
|
||||||
|
cata.MyList.Cons head tail |> myListStack.Add
|
||||||
|
|
||||||
|
myListStack
|
||||||
|
|
||||||
|
/// Execute the catamorphism.
|
||||||
|
let runMyList (cata : MyListCata<'a, 'MyListRet>) (x : MyList<'a>) : 'MyListRet =
|
||||||
|
let instructions = ResizeArray ()
|
||||||
|
instructions.Add (Instruction.Process__MyList x)
|
||||||
|
let myListRetStack = loop cata instructions
|
||||||
|
Seq.exactlyOne myListRetStack
|
||||||
|
namespace ConsumePlugin
|
||||||
|
|
||||||
|
open WoofWare.Myriad.Plugins
|
||||||
|
|
||||||
|
/// Description of how to combine cases during a fold
|
||||||
|
type MyList2CataCase<'a, 'MyList2> =
|
||||||
|
/// How to operate on the Nil case
|
||||||
|
abstract Nil : 'MyList2
|
||||||
|
/// How to operate on the Cons case
|
||||||
|
abstract Cons : 'a -> 'MyList2 -> 'MyList2
|
||||||
|
|
||||||
|
/// Specifies how to perform a fold (catamorphism) over the type MyList2 and its friends.
|
||||||
|
type MyList2Cata<'a, 'MyList2> =
|
||||||
|
{
|
||||||
|
/// How to perform a fold (catamorphism) over the type MyList2
|
||||||
|
MyList2 : MyList2CataCase<'a, 'MyList2>
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Methods to perform a catamorphism over the type MyList2
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module MyList2Cata =
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
type private Instruction<'a> =
|
||||||
|
| Process__MyList2 of MyList2<'a>
|
||||||
|
| MyList2_Cons of 'a
|
||||||
|
|
||||||
|
let private loop (cata : MyList2Cata<_, _>) (instructions : ResizeArray<Instruction<_>>) =
|
||||||
|
let myList2Stack = ResizeArray ()
|
||||||
|
|
||||||
|
while instructions.Count > 0 do
|
||||||
|
let currentInstruction = instructions.[instructions.Count - 1]
|
||||||
|
instructions.RemoveAt (instructions.Count - 1)
|
||||||
|
|
||||||
|
match currentInstruction with
|
||||||
|
| Instruction.Process__MyList2 x ->
|
||||||
|
match x with
|
||||||
|
| MyList2.Nil -> cata.MyList2.Nil |> myList2Stack.Add
|
||||||
|
| MyList2.Cons (arg0_0, arg1_0) ->
|
||||||
|
instructions.Add (Instruction.MyList2_Cons (arg0_0))
|
||||||
|
instructions.Add (Instruction.Process__MyList2 arg1_0)
|
||||||
|
| Instruction.MyList2_Cons (arg0_0) ->
|
||||||
|
let arg1_0 = myList2Stack.[myList2Stack.Count - 1]
|
||||||
|
myList2Stack.RemoveAt (myList2Stack.Count - 1)
|
||||||
|
cata.MyList2.Cons arg0_0 arg1_0 |> myList2Stack.Add
|
||||||
|
|
||||||
|
myList2Stack
|
||||||
|
|
||||||
|
/// Execute the catamorphism.
|
||||||
|
let runMyList2 (cata : MyList2Cata<'a, 'MyList2Ret>) (x : MyList2<'a>) : 'MyList2Ret =
|
||||||
|
let instructions = ResizeArray ()
|
||||||
|
instructions.Add (Instruction.Process__MyList2 x)
|
||||||
|
let myList2RetStack = loop cata instructions
|
||||||
|
Seq.exactlyOne myList2RetStack
|
||||||
Reference in New Issue
Block a user