# Motoko: debug\_show overload

**URL:** <https://forum.dfinity.org/t/motoko-debug-show-overload/16083>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [October 22, 2022, 4:31pm UTC](https://forum.dfinity.org/t/motoko-debug-show-overload/16083 "2022-10-22T16:31:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [October 22, 2022, 4:31pm UTC](https://forum.dfinity.org/t/motoko-debug-show-overload/16083/1 "2022-10-22T16:31:07Z")

</div>

Is there a way to overload what is run for debug\_show in motoko? We have an object with a member property that has a circular loop and it causes a stack overflow when trying to show it. We’d like to intercept and iterate only once through the object or skip it altogether.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 22, 2022, 7:51pm UTC](https://forum.dfinity.org/t/motoko-debug-show-overload/16083/2 "2022-10-22T19:51:14Z")

</div>

AFAIK solutions have been explored for this type of thing (see below) but there isn’t a way to do it at the moment.

- [Generalize debug\_show/serialization to support deriving traits for mono types · Issue #1500 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/1500)
- [[Feature Idea] Contextual method modules · Issue #2537 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/2537)

A long time ago I implemented similar things in userspace for showing, comparing, ordering, etc in Motoko but I don’t think the code is public.

I’ll follow up here with an example.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 23, 2022, 1:11am UTC](https://forum.dfinity.org/t/motoko-debug-show-overload/16083/3 "2022-10-23T01:11:16Z")

</div>

> **[GitHub - paulyoung/motoko-type-classes: A demonstration of how type classes...](https://github.com/paulyoung/motoko-type-classes)**
>
> A demonstration of how type classes can be approximated in Motoko, via manual "dictionary-passing" style. - GitHub - paulyoung/motoko-type-classes: A demonstration of how type classes can...
