Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Is it intended that traits cannot be satisfied by union types? #33

@pkalikman

Description

@pkalikman

E.g.:

using Traits

@traitdef SomeTrait{X} begin
    some_function(X) -> Int64
end

immutable TypeOne
    x::Float64
end

immutable TypeTwo
    x::Int64
end

typealias FloatOrInt Union{TypeOne,TypeTwo}

some_function(x::FloatOrInt) =  1

(edited by @mauro3)

istrait(SomeTrait{FloatOrInt})
ERROR: Traits.TraitException("Trait SomeTrait{Union{TypeOne,TypeTwo}} has no type parameters.")

I traced this in the source to hasparameters, which seems it rejects this type because the union type is not a DataType.

Is there a principled reason for that? Offhand I don't see why this trait shouldn't be satisfied by the example.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions