# Restrict dispatch domain

**URL:** <https://discourse.julialang.org/t/restrict-dispatch-domain/82953>\
**Category:** General Usage\
**Tags:** question, dispatch\
**Created:** [June 18, 2022, 5:57am UTC](https://discourse.julialang.org/t/restrict-dispatch-domain/82953 "2022-06-18T05:57:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [June 18, 2022, 5:57am UTC](https://discourse.julialang.org/t/restrict-dispatch-domain/82953/1 "2022-06-18T05:57:35Z")

</div>

```julia

formsumf(x :: Array{T,2}, A::Array{NTuple{3,T}} ) where T<: Number = sum(x*mapreduce(Base.splat(Base.vect),hcat, A))

julia> A=[(1,2,4),(3,5,4),(3,2,1),(9,2,6),(1,1,2)]
5-element Vector{Tuple{Int64, Int64, Int64}}:
 (1, 2, 4)
 (3, 5, 4)
 (3, 2, 1)
 (9, 2, 6)
 (1, 1, 2)

julia> x=[3 3 3]
1×3 Matrix{Int64}:
 3 3 3

julia> formsum(A,x)
1-element Vector{Int64}:
 138

julia> x=[3 3 3 ; 2 2 2]
2×3 Matrix{Int64}:
 3 3 3
 2 2 2

julia> formsum(A,x)
2-element Vector{Int64}:
 138
  92

julia> x=[3 3 3 4; 2 2 2 4]
2×4 Matrix{Int64}:
 3 3 3 4
 2 2 2 4

julia> formsum(x,A)
ERROR: DimensionMismatch("matrix A has dimensions (2,4), vector B has length 3")

```

I’m trying to practice using types in function definitions.  
Is there a way to force x to be an Nx3 matrix?

or the only way, if you want to introduce a control, is to do it in the body of the function with the if then else?
