{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f0a2a352-7250-4c87-b74b-4d629da60a3c", "metadata": {}, "outputs": [], "source": [ "struct Foo{T}\n", " a::T\n", " b::T\n", " Foo(a::T) where T = new{T}(a, a^2)\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "id": "c0edc25b-03c6-4ab0-aef7-1609ae06cbbd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 1 method for type constructor:" ], "text/plain": [ "# 1 method for type constructor:\n", "[1] Foo(a::T) where T in Main at In[1]:4" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo)" ] }, { "cell_type": "code", "execution_count": 3, "id": "f68ffec3-8a6d-4c3e-9b1a-8a0d6cdd8e51", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 0 methods for type constructor:" ], "text/plain": [ "# 0 methods for type constructor:" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo{Int})" ] }, { "cell_type": "code", "execution_count": 4, "id": "f4067302-ab25-42cc-9dba-f345015b72fb", "metadata": {}, "outputs": [], "source": [ "struct Foo{T}\n", " a::T\n", " b::T\n", " Foo(a::T) where T = new{T}(a, a^3)\n", "end" ] }, { "cell_type": "code", "execution_count": 5, "id": "2ea22ff0-673a-42eb-8fc9-ff59c758123d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 1 method for type constructor:" ], "text/plain": [ "# 1 method for type constructor:\n", "[1] Foo(a::T) where T in Main at In[4]:4" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo)" ] }, { "cell_type": "code", "execution_count": 6, "id": "0670360e-1d21-4866-a72a-db4f0fee796d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 0 methods for type constructor:" ], "text/plain": [ "# 0 methods for type constructor:" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo{Int})" ] }, { "cell_type": "code", "execution_count": 7, "id": "ae7c64fd-7e74-4fc6-a172-11c7e6bf9a58", "metadata": {}, "outputs": [], "source": [ "struct Foo{T}\n", " a::T\n", " b::T\n", " Foo(a::T) where T = new{T}(a, a^3)\n", " Foo(a::T, b::T) where T = new{T}(a, b)\n", "end" ] }, { "cell_type": "code", "execution_count": 8, "id": "4146fcc1-7d3f-43ac-98af-0a4eea95059c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 2 methods for type constructor:" ], "text/plain": [ "# 2 methods for type constructor:\n", "[1] Foo(a::T) where T in Main at In[7]:4\n", "[2] Foo(a::T, b::T) where T in Main at In[7]:5" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo)" ] }, { "cell_type": "code", "execution_count": 9, "id": "ee6b17c3-5370-4bab-97cf-af93b8ba9572", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 0 methods for type constructor:" ], "text/plain": [ "# 0 methods for type constructor:" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo{Int})" ] }, { "cell_type": "code", "execution_count": 10, "id": "40a3da35-b4cb-42b0-9c71-18f775b9e0c3", "metadata": {}, "outputs": [], "source": [ "struct Foo{T}\n", " a::T\n", " b::T\n", "end" ] }, { "cell_type": "code", "execution_count": 11, "id": "4acc3afc-6901-4f31-a902-4d552ded7f48", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 2 methods for type constructor:" ], "text/plain": [ "# 2 methods for type constructor:\n", "[1] Foo(a::T) where T in Main at In[7]:4\n", "[2] Foo(a::T, b::T) where T in Main at In[10]:2" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo)" ] }, { "cell_type": "code", "execution_count": 12, "id": "c07f4410-90cf-4855-97cb-187139676942", "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 1 method for type constructor:" ], "text/plain": [ "# 1 method for type constructor:\n", "[1] Foo{T}(a, b) where T in Main at In[10]:2" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(Foo{Int})" ] }, { "cell_type": "code", "execution_count": 13, "id": "3b9fc2f6-a2b9-40e0-932d-50b8b7ccf79f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Foo{Int64}(2, 8)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Foo(2)" ] }, { "cell_type": "code", "execution_count": 14, "id": "8ab8497a-424e-4a40-a5d6-653e08756324", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Foo{Int64}(2, 8)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Foo(2, 8)" ] }, { "cell_type": "code", "execution_count": 15, "id": "c4b307ed-32c5-4439-838b-20490f039ceb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Foo(2) == Foo(2, 8)" ] }, { "cell_type": "code", "execution_count": null, "id": "b2a16b6e-b95f-4322-b0b9-c21235c68b52", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.6.2", "language": "julia", "name": "julia-1.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.6.2" } }, "nbformat": 4, "nbformat_minor": 5 }