# Function subtypes

**URL:** https://discourse.julialang.org/t/function-subtypes/92292
**Category:** General Usage
**Created:** [December 29, 2022, 9:11pm UTC](https://discourse.julialang.org/t/function-subtypes/92292 "2022-12-29T21:11:30Z")
**Posts on this page:** 2
**Page:** 3

<div class="post-metadata">

### Author: ![nchisholm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nchisholm/32/37414_2.png) [@nchisholm](https://discourse.julialang.org/u/nchisholm)
#### Post date: [January 17, 2023, 8:05pm UTC](https://discourse.julialang.org/t/function-subtypes/92292/42 "2023-01-17T20:05:42Z")

</div>

Hmm… 🤔. How about leaving things more like your original macro:

```julia
abstract type MyAbstractType end

@singleton foo isa MyAbstractType

```

where the `@singleton` expands to

```julia
struct var"#foo" <: MyAbstractType end
const foo = var"#foo"()

```

Then it would be just a matter adjusting `Base.show` methods to nicely pretty-print things depending on whether the singleton instance `isa Function` or not.

```julia
julia> foo
foo (singleton)

julia> typeof(foo) # internally var"#foo", but that's transparent to the user
typeof(foo)

julia> abstract type MyFuncType <: Function end

julia> @singleton bar <: MyFuncType
bar (generic function with 0 methods)

julia> typeof(bar) # internally var"#bar"
typeof(bar)

```

This would not require any change to the language itself—only a new macro and adjustment of `Base.show`.

---

<div class="post-metadata">

### Author: ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)
#### Post date: [January 17, 2023, 8:38pm UTC](https://discourse.julialang.org/t/function-subtypes/92292/43 "2023-01-17T20:38:08Z")

</div>

You’re right. A macro makes more sense. I’m gonna edit my original answer (where the macro is defined) to use `isa` instead of `<:`, which i also think its better, and omit the `Base.show` definition.

[Previous page](https://discourse.julialang.org/t/function-subtypes/92292.md?page=2)
