👨‍💻 dev F sharp port

development

fukurou

the supreme coder
ADMIN
Code:
module AbsDictionaryDB

// Define the AbsDictionaryDB class
type AbsDictionaryDB() =
    member val Save: string -> string -> unit = fun _ _ -> printfn "Default Save method" with get, set
    member val Load: string -> string = fun _ -> "null" with get, set

// Declare an object outside the class
let dbInstance = AbsDictionaryDB()

// Override the object's methods dynamically
dbInstance.Save <- fun key value -> printfn "Saving: %s -> %s" key value
dbInstance.Load <- fun key -> sprintf "Loading key: %s" key

// Test the updated methods
dbInstance.Save "username" "fuki"
printfn "%s" (dbInstance.Load "username")
 

fukurou

the supreme coder
ADMIN
Code:
module LivinGrimorie

// Define the AbsDictionaryDB class
type AbsDictionaryDB() =
    member val Save: string -> string -> unit = fun _ _ -> printfn "Default Save method" with get, set
    member val Load: string -> string = fun _ -> "null" with get, set

// Declare an object outside the class
let dbInstance = AbsDictionaryDB()

// Override the object's methods dynamically
dbInstance.Save <- fun key value -> printfn "Saving: %s -> %s" key value
dbInstance.Load <- fun key -> sprintf "Loading key: %s" key

// Test the updated methods
dbInstance.Save "username" "fuki"
printfn "%s" (dbInstance.Load "username")

type Mutatable() =
    let mutable algKillSwitch: bool = false

    let mutable actionFunc: string -> string -> string -> string = fun _ _ _ -> "Default Action"
    let mutable completedFunc: unit -> bool = fun () -> false

    member this.AlgKillSwitch
        with get() = algKillSwitch
        and set(value) = algKillSwitch <- value

    member this.Action(ear: string, skin: string, eye: string) = actionFunc ear skin eye
    member this.Completed() = completedFunc()

    // Set function pointers dynamically
    member this.SetActionMethod(newAction: string -> string -> string -> string) = actionFunc <- newAction
    member this.SetCompletedMethod(newCompleted: unit -> bool) = completedFunc <- newCompleted

// Declare an instance outside the class
let mutatableInstance = Mutatable()

// Override function pointers dynamically
mutatableInstance.SetActionMethod(fun ear skin eye -> sprintf "Processing: %s, %s, %s" ear skin eye)
mutatableInstance.SetCompletedMethod(fun () -> true)

// Test the updated functions
printfn "%s" (mutatableInstance.Action("audio input", "touch input", "visual input"))

printfn "Completed: %b" (mutatableInstance.Completed())
 

fukurou

the supreme coder
ADMIN
Code:
type MyClass(value: int) =
    member this.Value = value
    member this.ExecuteFunction(f: MyClass -> int) =
        f this // Calls the function with the current instance

// Define a function that accesses the object's attribute
let getValue (obj: MyClass) = obj.Value

// Create an instance and pass the function
let instance = MyClass(42)
let result = instance.ExecuteFunction(getValue)

printfn "Result: %d" result
 

fukurou

the supreme coder
ADMIN
Code:
module LivinGrimorie
open System.Collections.Generic

// Define the AbsDictionaryDB class
type AbsDictionaryDB() =
    member val Save: string -> string -> unit = fun _ _ -> printfn "Default Save method" with get, set
    member val Load: string -> string = fun _ -> "null" with get, set

// Declare an object outside the class
let dbInstance = AbsDictionaryDB()

// Override the object's methods dynamically
dbInstance.Save <- fun key value -> printfn "Saving: %s -> %s" key value
dbInstance.Load <- fun key -> sprintf "Loading key: %s" key

// Test the updated methods
dbInstance.Save "username" "fuki"
printfn "%s" (dbInstance.Load "username")

// Define the interface to replicate Mutatable's behavior
type IMutatable =
    abstract member AlgKillSwitch: bool with get, set
    abstract member Action: string -> string -> string -> string
    abstract member Completed: unit -> bool
    abstract member MyName: unit -> string

// Implement APVerbatim using the IMutatable interface
type APVerbatim(sentences: string list) =
    let mutable algKillSwitch = false
    let mutable sentenceList = sentences

    interface IMutatable with
        member this.AlgKillSwitch
            with get() = algKillSwitch
            and set(value) = algKillSwitch <- value

        member this.Action ear skin eye =
            match sentenceList with
            | head :: tail ->
                sentenceList <- tail
                head
            | [] -> "" // Return empty string if no sentences left

        member this.Completed() =
            sentenceList.IsEmpty

        member this.MyName() =
            "APVerbatim"

// Test instance
let myVerbatim = APVerbatim(["Hello"; "World"])
let mutatableInstance = myVerbatim :> IMutatable

printfn "Class name: %s" (mutatableInstance.MyName())
printfn "Action result: %s" (mutatableInstance.Action "" "" "")
printfn "Completed? %b" (mutatableInstance.Completed())
printfn "Action result: %s" (mutatableInstance.Action "" "" "")
printfn "Completed? %b" (mutatableInstance.Completed())
 

fukurou

the supreme coder
ADMIN
Code:
type Algorithm(algParts: IMutatable list) =
    member this.AlgParts = algParts
    member this.Size = List.length algParts

// Create an instance of APVerbatim
let mutatableInstance = APVerbatim(["Test Sentence"]) :> IMutatable

// Now it can be passed to Algorithm
let algInstance = Algorithm([mutatableInstance])

printfn "Algorithm size: %d" algInstance.Size

// Access the first item in the Algorithm instance and call its Action method
match algInstance.AlgParts with
| head :: _ ->
    printfn "Action result: %s" (head.Action "input1" "input2" "input3")
| [] ->
    printfn "No elements in Algorithm."
 

fukurou

the supreme coder
ADMIN
Code:
// Define the Kokoro type
type Kokoro(grimoireMemento: AbsDictionaryDB) =
    let mutable emot = ""
    let toHeart = Dictionary<string, string>()

    member this.Emot
        with get() = emot
        and set(value) = emot <- value

    member this.GrimoireMemento = grimoireMemento
    member this.ToHeart = toHeart

// Create a test instance of AbsDictionaryDB
let testDB = AbsDictionaryDB()

// Create a test instance of Kokoro
let testKokoro = Kokoro(testDB)

// Set an emotion
testKokoro.Emot <- "Curious"
printfn "Emot set to: %s" testKokoro.Emot

// Store and retrieve values using toHeart
testKokoro.ToHeart.Add("question", "What is the meaning of life?")
printfn "Stored value in toHeart: %s" (testKokoro.ToHeart.["question"])

// Test saving and loading from AbsDictionaryDB
testKokoro.GrimoireMemento.Save "key1" "value1"
printfn "Loaded from DB: %s" (testKokoro.GrimoireMemento.Load "key1")
 

fukurou

the supreme coder
ADMIN
Code:
type Neuron() =
    let defcons = Dictionary<int, ResizeArray<Algorithm>>()

    do // Initialize the dictionary with priority levels
        for i in 1 .. 5 do
            defcons.Add(i, ResizeArray<Algorithm>())

    member this.InsertAlg(priority: int, alg: Algorithm) =
        if priority > 0 && priority < 6 then
            let algorithms = defcons.[priority]
            if algorithms.Count < 4 then
                algorithms.Add(alg)

    member this.GetAlg(defcon: int) =
        if defcons.[defcon].Count > 0 then
            let temp = defcons.[defcon].[0]
            defcons.[defcon].RemoveAt(0)
            Some temp
        else
            None
 

fukurou

the supreme coder
ADMIN
Code:
type Skill(initialKokoro: Kokoro option) =
    let mutable kokoro = initialKokoro
    let mutable outAlg: Algorithm option = None
    let mutable outpAlgPriority = -1

    // Getter and Setter for Kokoro
    member this.Kokoro
        with get() = kokoro
        and set(value) = kokoro <- value

    member this.Input(_ear: string, _skin: string, _eye: string) = ()

    member this.Output(neuron: Neuron) =
        match outAlg with
        | Some alg ->
            neuron.InsertAlg(outpAlgPriority, alg)
            outpAlgPriority <- -1
            outAlg <- None
        | None -> ()

    member this.SetKokoro(newKokoro: Kokoro) =
        this.Kokoro <- Some newKokoro

    member this.SetVerbatimAlg(priority: int, sayThis: string list) =
        outAlg <- Some (Algorithm([APVerbatim(sayThis)]))
        outpAlgPriority <- priority

    member this.SetSimpleAlg(sayThis: string list) =
        this.SetVerbatimAlg(4, sayThis)

    member this.SetVerbatimAlgFromList(priority: int, sayThis: string list) =
        outAlg <- Some (Algorithm([APVerbatim(sayThis)]))
        outpAlgPriority <- priority

    member this.AlgPartsFusion(priority: int, algParts: IMutatable list) =
        outAlg <- Some (Algorithm(algParts))
        outpAlgPriority <- priority

    member this.PendingAlgorithm() = outAlg.IsSome

    member this.SkillNotes(param: string) =
        match param with
        | "notes" -> "notes unknown"
        | _ -> "note unavailable"


type DiHelloWorld() =
    let baseSkill = Skill(None)

    member this.Input(ear: string, skin: string, eye: string) =
        match ear with
        | "hello" -> baseSkill.SetSimpleAlg(["hello world"])
        | _ -> ()

    member this.SkillNotes(param: string) =
        match param with
        | "notes" -> "plain hello world skill"
        | "triggers" -> "say hello"
        | _ -> "note unavailable"
 

fukurou

the supreme coder
ADMIN
Code:
type Cerabellum() =
    let mutable fin = 0
    let mutable at = 0
    let mutable incrementAt = false
    let mutable alg: Algorithm option = None
    let mutable isActive = false
    let mutable emot = ""

    // Advance in algorithm
    member this.AdvanceInAlg() =
        if incrementAt then
            incrementAt <- false
            at <- at + 1
            if at = fin then
                isActive <- false

    // Get current index position
    member this.GetAt() = at

    // Get current emotion
    member this.GetEmot() = emot

    // Set algorithm for execution
    member this.SetAlgorithm(algorithm: Algorithm) =
        if not isActive && algorithm.AlgParts.Length > 0 then
            alg <- Some algorithm
            at <- 0
            fin <- algorithm.Size
            isActive <- true
            emot <- algorithm.AlgParts.[at].MyName()


    // Check if active
    member this.IsActive() = isActive

    // Execute algorithm action
    member this.Act(ear: string, skin: string, eye: string) =
        match alg with
        | Some algorithm when isActive && at < fin ->
            let part = algorithm.AlgParts.[at]
            let axnStr = part.Action ear skin eye
            emot <- part.MyName()
            if part.Completed() then incrementAt <- true
            axnStr
        | _ -> ""

    // Deactivate algorithm if kill switch is triggered
    member this.DeActivation() =
        match alg with
        | Some algorithm when algorithm.AlgParts.[at].AlgKillSwitch -> isActive <- false
        | _ -> ()


type Fusion() =
    let mutable emot = ""
    let mutable result = ""
    let ceraArr = List.init 5 (fun _ -> Cerabellum()) // Creates 5 instances

    // Getter for emotion
    member this.Emot = emot

    // Load algorithms into Cerabellum instances from Neuron
    member this.LoadAlgs(neuron: Neuron) =
        for i in 1 .. 5 do
            let cera = ceraArr.[i - 1]
            if not (cera.IsActive()) then
                match neuron.GetAlg(i) with
                | Some temp -> cera.SetAlgorithm(temp) // Now correctly returns `unit`
                | None -> ()


    // Run algorithms by processing input
    member this.RunAlgs(ear: string, skin: string, eye: string) =
        let mutable localResult = ""
        for i in 0 .. 4 do
            if ceraArr.[i].IsActive() then
                localResult <- ceraArr.[i].Act (ear, skin, eye) // Fixed tuple application
                ceraArr.[i].AdvanceInAlg()
                emot <- ceraArr.[i].GetEmot()
                ceraArr.[i].DeActivation() // Check for kill switch
        localResult
 
Last edited:

fukurou

the supreme coder
ADMIN
kokoro cls update:
Code:
type Kokoro(initialGrimoireMemento: AbsDictionaryDB) =
    let mutable emot = ""
    let mutable grimoireMemento = initialGrimoireMemento
    let toHeart = Dictionary<string, string>()

    member this.Emot
        with get() = emot
        and set(value) = emot <- value

    member this.GrimoireMemento
        with get() = grimoireMemento
        and set(value) = grimoireMemento <- value

    member this.ToHeart = toHeart
 

fukurou

the supreme coder
ADMIN
Code:
type Chobits() =
    let mutable fusion = Fusion()
    let mutable noiron = Neuron()
    let mutable kokoro = Kokoro(AbsDictionaryDB())
    let mutable isThinking = false
    let mutable algTriggered = false

    let dClasses = ResizeArray<Skill>()
    let awareSkills = ResizeArray<Skill>()
    let cts_skills = ResizeArray<Skill>()

    // Set external database for Kokoro
    member this.SetDataBase(absDictionaryDB: AbsDictionaryDB) =
        kokoro.GrimoireMemento <- absDictionaryDB

    // Add a skill while ensuring proper telepathic connection
    member this.AddSkill(skill: Skill) =
        if not isThinking then
            skill.SetKokoro(kokoro)
            dClasses.Add(skill)

    member this.AddContinuousSkill(skill: Skill) =
        if not isThinking then
            skill.SetKokoro(kokoro)
            cts_skills.Add(skill)

    member this.AddSkillAware(skill: Skill) =
        skill.SetKokoro(kokoro)
        awareSkills.Add(skill)

    // Remove all stored skills (only if thinking isn't active)
    member this.ClearSkills() =
        if not isThinking then dClasses.Clear()

    member this.ClearContinuousSkills() =
        if not isThinking then cts_skills.Clear()

    member this.AddSkills(skills: Skill list) =
        if not isThinking then
            for skill in skills do
                skill.SetKokoro(kokoro)
                dClasses.Add(skill)

    member this.RemoveSkill(skill: Skill) =
        if not isThinking then dClasses.Remove(skill) |> ignore

    member this.RemoveContinuousSkill(skill: Skill) =
        if not isThinking then cts_skills.Remove(skill) |> ignore

    member this.ContainsSkill(skill: Skill) =
        dClasses.Contains(skill)

    // Thinking process: interacts with skills and fusion system
    member this.Think(ear: string, skin: string, eye: string) =
        algTriggered <- false
        isThinking <- true

        for skill in dClasses do
            this.InOut(skill, ear, skin, eye)

        isThinking <- false

        for skill in awareSkills do
            this.InOut(skill, ear, skin, eye)

        isThinking <- true

        for skill in cts_skills |> Seq.takeWhile (fun _ -> not algTriggered) do
            this.InOut(skill, ear, skin, eye)


        isThinking <- false
        fusion.LoadAlgs(noiron)
        fusion.RunAlgs(ear, skin, eye)

    // Retrieve current emotional state
    member this.GetSoulEmotion() =
        fusion.Emot

    // Handles skill input/output interaction
    member private this.InOut(skill: Skill, ear: string, skin: string, eye: string) =
        skill.Input(ear, skin, eye)
        if skill.PendingAlgorithm() then algTriggered <- true
        skill.Output(noiron)

    // Getters and setters for shared AI components
    member this.GetKokoro() = kokoro
    member this.SetKokoro(newKokoro: Kokoro) = kokoro <- newKokoro
    member this.GetFusion() = fusion

    // Retrieve a list of stored skills
    member this.GetSkillList() =
        dClasses |> Seq.map (fun s -> s.GetType().Name) |> Seq.toList
 

fukurou

the supreme coder
ADMIN
Code:
type Brain() =
    let mutable logicChobit = Chobits()
    let mutable hardwareChobit = Chobits()
    let mutable ear = Chobits()
    let mutable skin = Chobits()
    let mutable eye = Chobits()

    let mutable emotion = ""
    let mutable logicChobitOutput = ""

    do
        let kokoro = logicChobit.GetKokoro()
        let chobitsInstances = [hardwareChobit; ear; skin; eye]
        for chobit in chobitsInstances do
            chobit.SetKokoro(kokoro)

    // Getter for emotion
    member this.GetEmotion() = emotion

    // Getter for last output
    member this.GetLogicChobitOutput() = logicChobitOutput

    // Processing inputs (thinking cycle)
    member this.DoIt(earInput: string, skinInput: string, eyeInput: string) =
        logicChobitOutput <- logicChobit.Think(earInput, skinInput, eyeInput)
        emotion <- logicChobit.GetSoulEmotion()
        hardwareChobit.Think(logicChobitOutput, skinInput, eyeInput)

    // Handling direct and sensory inputs
    member this.Think(keyIn: string) =
        if keyIn <> "" then
            this.DoIt(keyIn, "", "")
        else
            this.DoIt(ear.Think("", "", ""), skin.Think("", "", ""), eye.Think("", "", ""))

    member this.Think() =
        this.DoIt(ear.Think("", "", ""), skin.Think("", "", ""), eye.Think("", "", ""))

    // Skill management
    member this.AddLogicalSkill(skill: Skill) = logicChobit.AddSkill(skill)
    member this.AddHardwareSkill(skill: Skill) = hardwareChobit.AddSkill(skill)
    member this.AddEarSkill(skill: Skill) = ear.AddSkill(skill)
    member this.AddSkinSkill(skill: Skill) = skin.AddSkill(skill)
    member this.AddEyeSkill(skill: Skill) = eye.AddSkill(skill)
 

fukurou

the supreme coder
ADMIN
Code:
type DiSysOut() =
    let baseSkill = Skill(None) // Composing Skill instead of inheriting

    member this.Input(ear: string, skin: string, eye: string) =
        if ear <> "" && not (ear.Contains("#")) then
            printfn "%s" ear
 

fukurou

the supreme coder
ADMIN
Code:
type DiHelloWorld() =
    let baseSkill = Skill(None)

    member this.AsSkill() : Skill = baseSkill // Exposes `baseSkill` properly

    member this.Input(ear: string, skin: string, eye: string) =
        match ear with
        | "hello" -> baseSkill.SetSimpleAlg(["hello world"])
        | _ -> ()

    member this.SkillNotes(param: string) =
        match param with
        | "notes" -> "plain hello world skill"
        | "triggers" -> "say hello"
        | _ -> "note unavailable"
 
Top