Repository: idris-hackers/idris-koans
Branch: master
Commit: 23d335932456
Files: 13
Total size: 11.1 KB
Directory structure:
gitextract_t4f2qm8w/
├── .gitignore
├── CONTRIBUTING.md
├── Koans/
│ ├── 01-Arithmetic.idr
│ ├── 02-Equality.idr
│ ├── 03-Boolean.idr
│ ├── 04-Ranges.idr
│ ├── 05-Lists.idr
│ ├── 06-ListComprehensions.idr
│ ├── 07-Tuples.idr
│ ├── 08-HigherOrderFunctions.idr
│ └── Misc.idr
├── LICENSE
└── README.md
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
\#*
\.#*
dist
cabal-dev/
.cabal-sandbox
cabal.sandbox.config
*.ibc
*.o
*.a
*.so
*.dll
*.dylib
*.swp
*~
.DS_Store
*.ibc
*~
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
.virthualenv
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to 'Idris Koans'
## Rules
* Please aim to make commits self contained. Ideally one thing at a time.
* Commit messages should have a brief (less than 73 characters) leading sentence. Together with a more detailed description where appropriate.
## Dev Process
For developing the project, we aim to follow the following [Git Branching Model](http://nvie.com/posts/a-successful-git-branching-model).
In this model there are two main branches:
* **master** Reflects the _current_ version of the tutorial inline with the _current_ version of Idris on Hackage.
* **dev** Reflects the latest upstream and current state of the tutorial.
All pull requests that are for new additions to the project should go to **dev**
All pull requests that detail fixes to the tutorial that is: grammar, spelling, and coding mistakes should be submitted to **master**
This might sound complicated but in the long term it makes sense in terms of release management.
================================================
FILE: Koans/01-Arithmetic.idr
================================================
-- | Some simple arithmetic exercises.
module Koans.Arithmetic
-- | There were 32 B/W Episodes of Ivor the Engine, and 72 episodes
-- were produced altogether. How many colour episodes were produced?
addition : Bool
addition = ?fillme1 + 32 == 72
-- | B/W Episodes of Ivor the Engine were ten minutes long. If you
-- were to watch all the episodes in one sitting how many minutes
-- would it take?
multiplication : Bool
multiplication = ?fillme2 == 10 * 32
-- | In what year did the Colourised version of Ivor the Engine first air?
subtraction : Bool
subtraction = 1977 - ?fillme3 == 3
-- | 26 B/W episodes of Ivor the Engine were discovered in a Pig shed
-- in 2010. There were two seasons. How many episodes per season were
-- there?
division : Bool
division = 26 / ?fillme4 == 2
-- | There were 32 B/W episodes of ten minutes each, and 40 colour
-- episodes of five minutes each. How many minutes of Ivor the Engine
-- exist?
parentheses : Int
parentheses = ?fillme5
-- --------------------------------------------------------------------- [ EOF ]
================================================
FILE: Koans/02-Equality.idr
================================================
-- | Exercises on Equality.
module Koans.Equality
equalityEq : Bool
equalityEq = ?fillme1 == True
equalityNeq : Bool
equalityNeq = ?fillme2 /= 3
equalityGeq : Bool
equalityGeq = ?fillme3 >= 4
equalityGtr : Bool
equalityGtr = ?fillme4 > 4
equalityLeq : Bool
equalityLeq = ?fillme5 <= 5
equalityLess : Bool
equalityLess = ?fillme6 < 6
-- --------------------------------------------------------------------- [ EOF ]
================================================
FILE: Koans/03-Boolean.idr
================================================
-- | Exercises on Boolean Relations.
module Koans.Boolean
logicalAND : Bool
logicalAND = True && ?fillme1 == True
logicalOR : Bool
logicalOR = False || ?fillme2 == False
logicalNOT : Bool
logicalNOT = not ?fillme3 == False
logicalPredicate : Bool
logicalPredicate = not ( ?fillme4 && True) || (?fillme5 && False) == True
-- --------------------------------------------------------------------- [ EOF ]
================================================
FILE: Koans/04-Ranges.idr
================================================
-- | Exercises on Ranges
module Koans.Ranges
rangeNums : Bool
rangeNums = ?fillme1 == [1..13]
stepUp : Bool
stepUp = ?fillme2 == [3,6..20]
stepDown : Bool
stepDown = ?fillme3 == [20,17..1]
stopMe : List Integer
stopMe = ?fillme4 [1..]
-- --------------------------------------------------------------------- [ EOF ]
================================================
FILE: Koans/05-Lists.idr
================================================
-- | Exercises on Lists
module Koans.Lists
-- | What is the type of this list.
nats : ?someType
nats = [0,1,2,3,4,5,6,7,9]
-- | Reproduce the list [0,1,3,5,7,9,2,4,6,8] using the following functions.
odds : List Int
odds = [1,3,5,7,9]
evens : List Int
evens = [2,4,6,8]
zero : Int
zero = 0
zeroOddsEvens : Bool
zeroOddsEvens = ?fillme2 ++ odds ++ ?fillme3 == [0,1,3,5,7,9,2,4,6,8]
-- | Complete the result of following functions.
headOList : Bool
headOList = ?fillme4 == Vect.head [5,4,3,2,1]
tailOList : Bool
tailOList = ?fillme5 == Vect.tail [0,1,2,3,4,5]
lastOList : Bool
lastOList = ?fillme6 == Vect.last [5,4,3,2,1]
initOList : Bool
initOList = ?fillme7 == Vect.init [1,2,3,4,5,6]
lengthOList : Bool
lengthOList = ?fillme8 == List.length [1,2,3,4,5]
reverseTheList : Bool
reverseTheList = ?fillme9 == List.reverse [1,2,3,4,5]
first3 : Bool
first3 = ?fillme10 == take 3 [1..10]
drop3 : Bool
drop3 = ?fillme11 == drop 3 [1..10]
countAllTheNumbers : Bool
countAllTheNumbers = ?fillme12 == sum [1..10]
timesAllTheNnumbers : Bool
timesAllTheNnumbers = ?fillme13 == product [1..10]
elementOrNot : Bool
elementOrNot = List.elem 4 ?fillme14 == True
-- | Make this function true
stopPete : Bool
stopPete = ?fillme15 (repeat 3) == [3,3,3,3]
-- --------------------------------------------------------------------- [ EOF ]
================================================
FILE: Koans/06-ListComprehensions.idr
================================================
module Koans.ListComprehensions
-- | What is the result of the List Comprehension.
listCompZero : Bool
listCompZero = ?fillme1 == with Classes [ x + x | x <- [1..5] ]
-- | Write a list comprehension that returns all the numbers divisible by four, doubled.
myFirstListComp : List Integer -> List Integer
myFirstListComp xs = ?fillme2
computeList : Bool
computeList = myFirstListComp [1..10] == [8,16]
-- | Return all the numbers between 20 and 100 that are divisible by 9.
divisibleByNine : List Integer
divisibleByNine = ?fillme3
-- | Using list comprehensions construct a function that turns a list of numbers into a list of strings.
-- Odd numbers should be bang, Even numbers boom.
boomBangs : List Integer -> List String
boomBangs xs = ?fillme4
where
transform : Integer -> String
transform = ?fillme5
doBoomBangs : Bool
doBoomBangs = boomBangs [3,4,5,6,7] == ["bang", "boom", "bang", "boom", "bang"]
================================================
FILE: Koans/07-Tuples.idr
================================================
module Koans.Tuples
-- Complete the following functions
firstPair : Bool
firstPair = ?fillme1 == fst ("First", "Pair")
secondPair : Bool
secondPair = ?fillme2 == snd ("Second", "Pair")
whatAmI : Vect 5 (Int, Bool)
whatAmI = ?fillme3
ws : Vect 5 String
ws = ["zip", "a", "dee", "doo", "dah"]
is : Vect 5 Int
is = ?fillme4
myFirstZip : Bool
myFirstZip = zip ws is == ?fillme5
whatIsMyResult : Bool
whatIsMyResult = ?fillme6 == Vect.zipWith (+) is is
================================================
FILE: Koans/08-HigherOrderFunctions.idr
================================================
module Koans.HigherOrderFunctions
-- Complete these functions
-- Maps are used to map a function to elements in a list.
myFirstMap : Bool
myFirstMap = ?fillme1 == map (2*) [1..4]
mySecondMap : Bool
mySecondMap = [1, 4, 9, 16, 25] == map ?fillme2 [1..5]
myThirdMap : Bool
myThirdMap = [25, 16, 9, 4, 1] == map ?fillme3 [1..5]
-- Folds are used to combine elements in a list from start to finish using a function.
myFirstFold : Bool
myFirstFold = foldl (+) 0 [1..4] == ?fillme4
mySecondFold : Bool
mySecondFold = 5 == foldl ?fillme5 5 [1..4]
-- Scans are like fold but you see the intermediate results, and then the result.
myFirstScan : Bool
myFirstScan = scanl (max) 5 [1,2,3,4] == ?fillme6
mySecondScan : Bool
mySecondScan = scanl ?fillme7 5 [1,2,10,1] == [5,5,5,10,10]
myThirdScan : Bool
myThirdScan = scanl (/) 64 [4,2,4] == ?fillme8
-- TODO Add examples for scanr and foldr
-- You can filter things as well.
xs : List Int
xs = [1,2,3,4,5,6,7,8,9,10]
myFirstFilter : Bool
myFirstFilter = filter (>5) xs == ?fillme15
mySecondFilter : Bool
mySecondFilter = filter ?fillme16 [10,20,30,40,50,60,70,80,90,100] == xs
-- You can combine functions as well
myFirstCombi : Bool
myFirstCombi = ["bang", "boom", "bang", "boom", "bang"] == map ?fillme17 (filter ?fillme18 xs)
================================================
FILE: Koans/Misc.idr
================================================
module Misc
smallOdds : List Integer
smallOdds = [x | x <- [1..20], Builtins.mod x 2 == 0 ]
greeter : String -> String
greeter whom = "Hello to " ++ whom
================================================
FILE: LICENSE
================================================
Copyright (c) 2013, Idris Hackers
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: README.md
================================================
idris-koans
===========
Koans are small lessons on the path to enlightenment.
Previously, the _Koans_ method of learning a language has be used by both: [Clojure](http://clojurekoans.com/), [Clojurescript](http://clojurescriptkoans.com/), and [Ruby](http://rubykoans.com/).
With Ruby Koans being the initial Koans project.
The aim of the Idris Koans project is to provide an easy learning environment in which you can learn Idris, and Functional Programming (FP).
Insight will be derived by encountering 'failing' code that requires fixing.
By fixing the code you will learn more about Idris and FP.
Within the `Koans` folder you will find the various lessons.
Each lesson addresses various topics within FP, and also specific to Idris.
Each lesson consists of a series of functions that when passed through the Idris compiler will either: fail to type check, or have the wrong behaviour.
To pass each lesson each function needs to be completed or fixed so that it type checks, or has deterministic behaviour.
The files should be attempted in the following order:
1. 01-Arithmetic.idr
1. 02-Equality.idr
1. 03-Boolean.idr
1. 04-Ranges.idr
1. 05-Lists.idr
1. 06-ListComprehensions.idr
Idris Koans is in early development and so the list of Koans and method of interaction is primitive.
If you would like to contribute please feel free to do so.
However, please read [CONTRIBUTING.md] first.
We advised the best way to attempt each Koan is to edit the Koan file in your favourite editor, and compile each Koan in the terminal using the Idris compiler.
In future a more interactive environment may be planned.
Either a CLI/REPL environment _a la_ [Clojure Koans](http://clojurekoans.com/), or Web Based _a la_ [Clojurescript Koans](http://clojurescriptkoans.com/) may be added.
The latest stable release of Idris can easily be installed using cabal:
$ cabal update; cabal install idris
Although you can also install Idris from source.
For editing Idris there is support for both the [Emacs](https://github.com/idris-hackers/idris-mode) and [Vim](https://github.com/idris-hackers/idris-vim) editors.
More information concerning Idris can be found online from:
* [idris-lang](http://www.idris-lang.org/)
* [idris-tutorial](https://github.com/idris-hackers/idris-tutorial)
* [idris-hackers](http://idris-hackers.github.io/)
gitextract_t4f2qm8w/ ├── .gitignore ├── CONTRIBUTING.md ├── Koans/ │ ├── 01-Arithmetic.idr │ ├── 02-Equality.idr │ ├── 03-Boolean.idr │ ├── 04-Ranges.idr │ ├── 05-Lists.idr │ ├── 06-ListComprehensions.idr │ ├── 07-Tuples.idr │ ├── 08-HigherOrderFunctions.idr │ └── Misc.idr ├── LICENSE └── README.md
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (12K chars).
[
{
"path": ".gitignore",
"chars": 175,
"preview": "\\#*\n\\.#*\n\ndist\ncabal-dev/\n.cabal-sandbox\ncabal.sandbox.config\n*.ibc\n*.o\n*.a\n*.so\n*.dll\n*.dylib\n*.swp\n*~\n.DS_Store\n\n*.ibc"
},
{
"path": "CONTRIBUTING.md",
"chars": 962,
"preview": "# Contributing to 'Idris Koans'\n\n## Rules\n\n* Please aim to make commits self contained. Ideally one thing at a time.\n* C"
},
{
"path": "Koans/01-Arithmetic.idr",
"chars": 1062,
"preview": "-- | Some simple arithmetic exercises.\nmodule Koans.Arithmetic\n\n-- | There were 32 B/W Episodes of Ivor the Engine, and "
},
{
"path": "Koans/02-Equality.idr",
"chars": 421,
"preview": "-- | Exercises on Equality.\nmodule Koans.Equality\n\nequalityEq : Bool\nequalityEq = ?fillme1 == True\n\nequalityNeq : Bool\ne"
},
{
"path": "Koans/03-Boolean.idr",
"chars": 407,
"preview": "-- | Exercises on Boolean Relations.\nmodule Koans.Boolean\n\nlogicalAND : Bool\nlogicalAND = True && ?fillme1 == True\n\nlogi"
},
{
"path": "Koans/04-Ranges.idr",
"chars": 321,
"preview": "-- | Exercises on Ranges\nmodule Koans.Ranges\n\nrangeNums : Bool\nrangeNums = ?fillme1 == [1..13]\n\nstepUp : Bool\nstepUp = ?"
},
{
"path": "Koans/05-Lists.idr",
"chars": 1336,
"preview": "-- | Exercises on Lists\nmodule Koans.Lists\n\n-- | What is the type of this list.\nnats : ?someType\nnats = [0,1,2,3,4,5,6,7"
},
{
"path": "Koans/06-ListComprehensions.idr",
"chars": 962,
"preview": "module Koans.ListComprehensions\n\n-- | What is the result of the List Comprehension.\nlistCompZero : Bool\nlistCompZero = ?"
},
{
"path": "Koans/07-Tuples.idr",
"chars": 456,
"preview": "module Koans.Tuples\n\n-- Complete the following functions\n\nfirstPair : Bool\nfirstPair = ?fillme1 == fst (\"First\", \"Pair\")"
},
{
"path": "Koans/08-HigherOrderFunctions.idr",
"chars": 1286,
"preview": "module Koans.HigherOrderFunctions\n\n-- Complete these functions\n\n-- Maps are used to map a function to elements in a list"
},
{
"path": "Koans/Misc.idr",
"chars": 157,
"preview": "module Misc\n\nsmallOdds : List Integer\nsmallOdds = [x | x <- [1..20], Builtins.mod x 2 == 0 ]\n\ngreeter : String -> String"
},
{
"path": "LICENSE",
"chars": 1489,
"preview": "Copyright (c) 2013, Idris Hackers\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or witho"
},
{
"path": "README.md",
"chars": 2333,
"preview": "idris-koans\n===========\n\nKoans are small lessons on the path to enlightenment.\nPreviously, the _Koans_ method of learnin"
}
]
About this extraction
This page contains the full source code of the idris-hackers/idris-koans GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (11.1 KB), approximately 3.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.