Skip to content

Instantly share code, notes, and snippets.

@Garciat
Created November 25, 2025 16:11
Show Gist options
  • Select an option

  • Save Garciat/9829f8d19347efe21d4e7a0898a8e71b to your computer and use it in GitHub Desktop.

Select an option

Save Garciat/9829f8d19347efe21d4e7a0898a8e71b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2aa8279b-28bc-498c-a6cf-3124f1ece482",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"{-\n",
"interface Equality<T> {\n",
" boolean isEqual(T x, T y);\n",
"}\n",
"-}\n",
"\n",
"class Equality a where\n",
" isEqual :: a -> a -> Bool"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6e5633d3-679a-4a7d-9835-2470b6267ce5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"data Point = Point Int Int\n",
"\n",
"instance Equality Point where\n",
" isEqual (Point ax ay) (Point bx by) = ax == bx && ay == by"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "499ac38b-0b22-4e35-a361-ac9af7bb6510",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"code CodeMirror cm-s-jupyter cm-s-ipython\"><span class=\"cm-keyword\">type</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Point</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">::</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">*</span><span class=\"cm-space\"><br /></span>\n",
"<span class=\"cm-keyword\">data</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Point</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">=</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Point</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Int</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Int</span><span class=\"cm-space\"><br /> \t</span><span class=\"cm-comment\">-- Defined at <interactive>:1:1</span><span class=\"cm-space\"><br /></span>\n",
"<span class=\"cm-keyword\">instance</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">[</span><span class=\"cm-keyword\">safe</span><span class=\"cm-atom\">]</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Equality</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Point</span><span class=\"cm-space\"> </span><span class=\"cm-comment\">-- Defined at <interactive>:2:10</span><span class=\"cm-space\"><br /></span></div>"
],
"text/plain": [
"type Point :: *\n",
"data Point = Point Int Int\n",
" \t-- Defined at <interactive>:1:1\n",
"instance [safe] Equality Point -- Defined at <interactive>:2:10"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":i Point"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "c319939d-0a77-4c16-80eb-62902436e052",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
"display: block;\n",
"padding-bottom: 1.3em;\n",
"padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
"display: block;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"}\n",
".hoogle-text {\n",
"display: block;\n",
"}\n",
".hoogle-name {\n",
"color: green;\n",
"font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
"display: block;\n",
"margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
"font-weight: bold;\n",
"font-style: italic;\n",
"}\n",
".hoogle-module {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
"font-weight: bold;\n",
"}\n",
"\n",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
"\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\n",
"\n",
".suggestion-warning { \n",
"font-weight: bold;\n",
"color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
"font-weight: bold;\n",
"color: red;\n",
"}\n",
".suggestion-name {\n",
"font-weight: bold;\n",
"}\n",
"\n",
"</style><span class='get-type'>Point :: Int -> Int -> Point</span>"
],
"text/plain": [
"Point :: Int -> Int -> Point"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":t Point"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b0139bbc-35ef-43fe-9149-3d745187867d",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"isEqual (Point 1 2) (Point 1 2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "827cfc3e-c5a9-4d91-89cf-78caf2830079",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"isEqual (Point 5 2) (Point 1 2)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "525e1363-3ab6-4b6a-8462-ed923252ec8a",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
"display: block;\n",
"padding-bottom: 1.3em;\n",
"padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
"display: block;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"}\n",
".hoogle-text {\n",
"display: block;\n",
"}\n",
".hoogle-name {\n",
"color: green;\n",
"font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
"display: block;\n",
"margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
"font-weight: bold;\n",
"font-style: italic;\n",
"}\n",
".hoogle-module {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
"font-weight: bold;\n",
"}\n",
"\n",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
"\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\n",
"\n",
".suggestion-warning { \n",
"font-weight: bold;\n",
"color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
"font-weight: bold;\n",
"color: red;\n",
"}\n",
".suggestion-name {\n",
"font-weight: bold;\n",
"}\n",
"\n",
"</style><span class='get-type'>isEqual :: forall a. Equality a => a -> a -> Bool</span>"
],
"text/plain": [
"isEqual :: forall a. Equality a => a -> a -> Bool"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":t isEqual"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "21a0f023-d542-41e7-b107-644a088ee8fa",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"contains :: Equality a => [a] -> a -> Bool\n",
"contains [] _ = False\n",
"contains (x:xs) target = if isEqual x target then True else contains xs target"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "3a2c02ef-0532-4ac2-9c36-340136c88bb5",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"contains [Point 1 1, Point 1 2] (Point 1 4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86359cd2-4861-4c14-90e1-e41aad4a0001",
"metadata": {},
"outputs": [],
"source": [
"id :: a -> a\n",
"pair :: a -> (a, a)\n",
"singleton :: a -> [a]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d576f598-2cb7-449e-b899-9cc2b171d944",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"instance Equality a => Equality (Maybe a) where\n",
" isEqual Nothing Nothing = True\n",
" isEqual (Just x) (Just y) = isEqual x y\n",
" isEqual _ _ = False"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "41b8349e-42cd-4a9e-9391-479980fe7551",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"contains [Nothing, Just (Just (Point 1 1))] (Just (Just (Point 1 2)))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "7f15d857-f2e6-47b2-93c6-3c300d67a206",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
"display: block;\n",
"padding-bottom: 1.3em;\n",
"padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
"display: block;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"}\n",
".hoogle-text {\n",
"display: block;\n",
"}\n",
".hoogle-name {\n",
"color: green;\n",
"font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
"display: block;\n",
"margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
"font-weight: bold;\n",
"font-style: italic;\n",
"}\n",
".hoogle-module {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
"font-weight: bold;\n",
"}\n",
"\n",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
"\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\n",
"\n",
".suggestion-warning { \n",
"font-weight: bold;\n",
"color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
"font-weight: bold;\n",
"color: red;\n",
"}\n",
".suggestion-name {\n",
"font-weight: bold;\n",
"}\n",
"\n",
"</style><span class='get-type'>(==) :: forall a. Eq a => a -> a -> Bool</span>"
],
"text/plain": [
"(==) :: forall a. Eq a => a -> a -> Bool"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":t (==)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "49f0a029-f410-410b-a346-d79b7adfc8a0",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"succ 1"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "55f044e5-0f0d-4695-a607-b5badc167111",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[1,2,3,4,5,6,7,8,9,10]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"[1..10]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9eb256df-6d84-4fca-aebf-7ccdf9ba5aa8",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[1,2,3,4,5,6,7,8,9,10]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"enumFromTo 1 10"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62917695-d036-43ff-bbc4-748408b46c15",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
"display: block;\n",
"padding-bottom: 1.3em;\n",
"padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
"display: block;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"}\n",
".hoogle-text {\n",
"display: block;\n",
"}\n",
".hoogle-name {\n",
"color: green;\n",
"font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
"display: block;\n",
"margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
"font-weight: bold;\n",
"font-style: italic;\n",
"}\n",
".hoogle-module {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
"font-weight: bold;\n",
"}\n",
"\n",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
"\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\n",
"\n",
".suggestion-warning { \n",
"font-weight: bold;\n",
"color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
"font-weight: bold;\n",
"color: red;\n",
"}\n",
".suggestion-name {\n",
"font-weight: bold;\n",
"}\n",
"\n",
"</style><span class='get-type'>enumFromTo :: forall a. Enum a => a -> a -> [a]</span>"
],
"text/plain": [
"enumFromTo :: forall a. Enum a => a -> a -> [a]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":t enumFromTo"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13d085c1-eee7-4aa6-9bd6-f46c53e1f018",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"code CodeMirror cm-s-jupyter cm-s-ipython\"><span class=\"cm-keyword\">type</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Enum</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">::</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">*</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">-></span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Constraint</span><span class=\"cm-space\"><br /></span>\n",
"<span class=\"cm-keyword\">class</span><span class=\"cm-space\"> </span><span class=\"cm-variable-2\">Enum</span><span class=\"cm-space\"> </span><span class=\"cm-variable\">a</span><span class=\"cm-space\"> </span><span class=\"cm-keyword\">where</span><span class=\"cm-space\"><br /> </span><span class=\"cm-operator\">...</span><span class=\"cm-space\"><br /> </span><span class=\"cm-variable\">enumFromTo</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">::</span><span class=\"cm-space\"> </span><span class=\"cm-variable\">a</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">-></span><span class=\"cm-space\"> </span><span class=\"cm-variable\">a</span><span class=\"cm-space\"> </span><span class=\"cm-atom\">-></span><span class=\"cm-space\"> </span><span class=\"cm-atom\">[</span><span class=\"cm-variable\">a</span><span class=\"cm-atom\">]</span><span class=\"cm-space\"><br /> </span><span class=\"cm-operator\">...</span><span class=\"cm-space\"><br /> \t</span><span class=\"cm-comment\">-- Defined in ‘GHC.Enum’</span><span class=\"cm-space\"><br /></span></div>"
],
"text/plain": [
"type Enum :: * -> Constraint\n",
"class Enum a where\n",
" ...\n",
" enumFromTo :: a -> a -> [a]\n",
" ...\n",
" \t-- Defined in ‘GHC.Enum’"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":i enumFromTo"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"codemirror_mode": "ihaskell",
"file_extension": ".hs",
"mimetype": "text/x-haskell",
"name": "haskell",
"pygments_lexer": "Haskell",
"version": "9.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment