// Generated by purs version 0.14.5
"use strict";
var Data_Boolean = require("../Data.Boolean/index.js");
var Data_EuclideanRing = require("../Data.EuclideanRing/index.js");
var Data_Ordering = require("../Data.Ordering/index.js");
var Data_Semigroup = require("../Data.Semigroup/index.js");
var Data_Symbol = require("../Data.Symbol/index.js");
var Data_Unit = require("../Data.Unit/index.js");
var Record_Unsafe = require("../Record.Unsafe/index.js");
var Type_Proxy = require("../Type.Proxy/index.js");
var monoidUnit = {
    mempty: Data_Unit.unit,
    Semigroup0: function () {
        return Data_Semigroup.semigroupUnit;
    }
};
var monoidString = {
    mempty: "",
    Semigroup0: function () {
        return Data_Semigroup.semigroupString;
    }
};
var monoidRecordNil = {
    memptyRecord: function (v) {
        return {};
    },
    SemigroupRecord0: function () {
        return Data_Semigroup.semigroupRecordNil;
    }
};
var monoidOrdering = {
    mempty: Data_Ordering.EQ.value,
    Semigroup0: function () {
        return Data_Ordering.semigroupOrdering;
    }
};
var monoidArray = {
    mempty: [  ],
    Semigroup0: function () {
        return Data_Semigroup.semigroupArray;
    }
};
var memptyRecord = function (dict) {
    return dict.memptyRecord;
};
var monoidRecord = function (dictRowToList) {
    return function (dictMonoidRecord) {
        return {
            mempty: memptyRecord(dictMonoidRecord)(Type_Proxy["Proxy"].value),
            Semigroup0: function () {
                return Data_Semigroup.semigroupRecord()(dictMonoidRecord.SemigroupRecord0());
            }
        };
    };
};
var mempty = function (dict) {
    return dict.mempty;
};
var monoidFn = function (dictMonoid) {
    return {
        mempty: function (v) {
            return mempty(dictMonoid);
        },
        Semigroup0: function () {
            return Data_Semigroup.semigroupFn(dictMonoid.Semigroup0());
        }
    };
};
var monoidRecordCons = function (dictIsSymbol) {
    return function (dictMonoid) {
        return function (dictCons) {
            return function (dictMonoidRecord) {
                return {
                    memptyRecord: function (v) {
                        var tail = memptyRecord(dictMonoidRecord)(Type_Proxy["Proxy"].value);
                        var key = Data_Symbol.reflectSymbol(dictIsSymbol)(Type_Proxy["Proxy"].value);
                        var insert = Record_Unsafe.unsafeSet(key);
                        return insert(mempty(dictMonoid))(tail);
                    },
                    SemigroupRecord0: function () {
                        return Data_Semigroup.semigroupRecordCons(dictIsSymbol)()(dictMonoidRecord.SemigroupRecord0())(dictMonoid.Semigroup0());
                    }
                };
            };
        };
    };
};
var power = function (dictMonoid) {
    return function (x) {
        var go = function (p) {
            if (p <= 0) {
                return mempty(dictMonoid);
            };
            if (p === 1) {
                return x;
            };
            if (Data_EuclideanRing.mod(Data_EuclideanRing.euclideanRingInt)(p)(2) === 0) {
                var x$prime = go(Data_EuclideanRing.div(Data_EuclideanRing.euclideanRingInt)(p)(2));
                return Data_Semigroup.append(dictMonoid.Semigroup0())(x$prime)(x$prime);
            };
            if (Data_Boolean.otherwise) {
                var x$prime = go(Data_EuclideanRing.div(Data_EuclideanRing.euclideanRingInt)(p)(2));
                return Data_Semigroup.append(dictMonoid.Semigroup0())(x$prime)(Data_Semigroup.append(dictMonoid.Semigroup0())(x$prime)(x));
            };
            throw new Error("Failed pattern match at Data.Monoid (line 86, column 3 - line 86, column 17): " + [ p.constructor.name ]);
        };
        return go;
    };
};
var guard = function (dictMonoid) {
    return function (v) {
        return function (v1) {
            if (v) {
                return v1;
            };
            if (!v) {
                return mempty(dictMonoid);
            };
            throw new Error("Failed pattern match at Data.Monoid (line 94, column 1 - line 94, column 49): " + [ v.constructor.name, v1.constructor.name ]);
        };
    };
};
module.exports = {
    mempty: mempty,
    power: power,
    guard: guard,
    memptyRecord: memptyRecord,
    monoidUnit: monoidUnit,
    monoidOrdering: monoidOrdering,
    monoidFn: monoidFn,
    monoidString: monoidString,
    monoidArray: monoidArray,
    monoidRecord: monoidRecord,
    monoidRecordNil: monoidRecordNil,
    monoidRecordCons: monoidRecordCons
};
