Skip to content
This repository has been 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

Open
pkalikman opened this issue Apr 5, 2016 · 2 comments
Open

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

pkalikman opened this issue Apr 5, 2016 · 2 comments

Comments

@pkalikman
Copy link

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

@mauro3
Copy link
Owner

mauro3 commented Apr 5, 2016

Yes, I think this should work but is not implemented at the moment. If a trait is fulfilled for all types of a union then the union should be part of the trait too.

@mauro3
Copy link
Owner

mauro3 commented Apr 6, 2016

I not gonna have time to work on this for a few weeks. If you want to have a crack at it, probably need to insert a loop at

which loops over all unions and calls istrait recursively.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants