Constrained genericity: Difference between revisions
Content deleted Content added
Type constraints are against Tcl's general philosophy, so this challenge is inappropriate |
add E example |
||
Line 136: | Line 136: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|E}}== |
|||
It is surely arguable whether this constitutes an implementation of the above task: |
|||
<lang e> |
|||
/** Guard accepting only objects with an 'eat' method */ |
|||
def Eatable { |
|||
to coerce(specimen, ejector) { |
|||
if (Ref.isNear(specimen) && specimen.__respondsTo("eat", 0)) { |
|||
return specimen |
|||
} else { |
|||
throw.eject(ejector, `inedible: $specimen`) |
|||
} |
|||
} |
|||
} |
|||
def makeFoodBox() { |
|||
return [].diverge(Eatable) # A guard-constrained list |
|||
}</lang> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |