Skip to main content

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2$\mathbb{R}^2$):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share — in Mathematica — the same signature, which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share — in Mathematica — the same signature, which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in $\mathbb{R}^2$):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share — in Mathematica — the same signature, which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

Tweeted twitter.com/#!/StackMma/status/389002690933850112
Improved formatting
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] :=  {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share -- in Mathematica -- the same signature, which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share -- in Mathematica -- the same signature which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] :=  {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share in Mathematica the same signature, which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

( ForFor educational purposes  ) I defined the following functions:

Translation (in R2$\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in R2$\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share -in Mathematica- in Mathematica -- the same signature which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a MathematicaMathematica function to enforce polymorphism?

( For educational purposes  ) I defined the following functions:

Translation (in R2):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in R2):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share -in Mathematica- the same signature which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

(For educational purposes) I defined the following functions:

Translation (in $\mathbb{R}^2$):

trM[vec_] := {{1, 0, vec[[1]]}, {0, 1, vec[[2]]}, {0, 0, 1}} 

Rotation (in R2):

rotM[angle_] := {{Cos[angle], -Sin[angle], 0}, {Sin[angle], Cos[angle], 0}, {0, 0, 1}} 

Rotation around a point (in $\mathbb{R}^2$):

rotM[pt_, angle_] := trM[pt].rotM[angle].trM[-pt] 

So far so good, now I want a function:

rotM[angle_, n_] := {{Cos[n angle], -Sin[n angle], 0}, {Sin[n angle], Cos[n angle], 0}, {0, 0, 1}} 

Now

 rotM[angle_, n_] 

and

rotM[pt_, angle_] 

share -- in Mathematica -- the same signature which breaks the polymorphism I intended to use, which then leads to the following question.

How can I type-check the arguments of a Mathematica function to enforce polymorphism?

Source Link
nilo de roock
  • 9.7k
  • 3
  • 36
  • 81
Loading