From 263444c2a944c36d147bb32ca8e03acff2b79575 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 04:16:21 +0100 Subject: [PATCH] add basic fallbacks --- src/Groups.jl | 18 +----------------- src/fallbacks.jl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 src/fallbacks.jl diff --git a/src/Groups.jl b/src/Groups.jl index 6a53c04..76d3752 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -14,25 +14,9 @@ using LinearAlgebra using Markdown -Base.one(G::Generic.PermGroup) = Generic.Perm(G.n) -Base.one(r::NCRingElem) = one(parent(r)) - -############################################################################### -# -# ParentType / ObjectType definition -# - include("types.jl") include("gsymbols.jl") - -function Base.one(G::Gr) where Gr <: AbstractFPGroup - El = elem_type(G) - id = El(eltype(El)[]) - id.parent = G - return id -end - -elem_type(G::Gr) where Gr <:AbstractFPGroup = elem_type(Gr) # fallback definition +include("fallbacks.jl") @doc doc""" diff --git a/src/fallbacks.jl b/src/fallbacks.jl new file mode 100644 index 0000000..bc1d1db --- /dev/null +++ b/src/fallbacks.jl @@ -0,0 +1,17 @@ +# workarounds +Base.one(G::Generic.PermGroup) = Generic.Perm(G.n) +Base.one(r::NCRingElem) = one(parent(r)) + +# fallback definitions +# note: the user should implement those on type, when possible +Base.eltype(w::GW) where GW<:GWord = eltype(GW) +AbstractAlgebra.elem_type(G::Gr) where Gr <:AbstractFPGroup = elem_type(Gr) + +AbstractAlgebra.parent_type(g::Gw) where Gw <:GWord = parent_type(parent(Gr)) + +function Base.one(G::Gr) where Gr <: AbstractFPGroup + El = elem_type(G) + id = El(eltype(El)[]) + id.parent = G + return id +end