Answers.Body: <p>You want an approach that aligns to the problems typed functional programming languages like Haskell lend themselves well to. That is to say, Category Theory + Tensor data. So the best problems to solve would likely be those involving linear algebra.</p>
  <p>Example:</p>
  <ul>
  <li>Start with implementing scalar arithmetic (custom types and functions and all. Intro to Monads / Maybe for NaNs and such)(1 hour)</li>
  <li>next ask them to build on the last example but implement vectors (again, all custom types, higher order functions)(1 hour)</li>
  <li>next ask them to do the same but with Matrix (Kernels, Images, custom types, higher order functions)(1 hour)</li>
  <li>next ask them to do the same but a linear solver (so det, eigenvectors and values)(1 hour)</li>
  <li>finally ask them implement Principal Components Analysis (so learn about files and loading data)(1 hour)</li>
  <li>leave them with a question at the end to further build off the work:
  <ul>
  <li>What is the principal component of a tensor? (if they coded things right, they'll have a joy of exploration )</li>
  <li>How would you implement formulas and derivative functions? (abstract a part of the linear solver from before)</li>
  <li>How would you implement graphs and graphing algorithms? (matrix implementation vs association list)</li>
  <li>How would you rewrite the library for Tensors of infinite size, or how would you implement dynamic programming problems? (intro to functional reactive streams)</li>
  </ul>
  </li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-13T12:58:56.677Z
Answers.LastActivityDate: 2023-01-13T12:58:56.677Z
Answers.UserDisplayName: hussaibi
Answers.Body: <h1>The ideas in your question are far too difficult, for a one hour introduction.</h1>
  <p>Yesterday I had a look at Haskell and learnt some. I have over 30 years programming experience (20 years professional). Have experience with functional programming. Yet it took me several hours, and did not get far enough to be able to do your suggestions.</p>
  <h1>Mathematics</h1>
  <p>You say that your students have a maths background.</p>
  <p>Take advantage of this. Choose some math problems. That Haskell is ideally suited to solve. And explain why you are doing this.</p>
  <p>Ensure that you have more than you think you will need, as some students will be much faster than you expect, but don't expect to use them all.</p>
  <p>There are some good ideas here <a href="https://stackoverflow.com/a/15110828/537980">https://stackoverflow.com/a/15110828/537980</a> also some of the other answers, to the same question: sort, search, interpreter (this one may take too long), factorial.</p>
  <h1>Avoid bad examples</h1>
  <p>Don't do problems that are more difficult in a functional language than in a procedural one (Reversing a list, using procedural techniques, in <span class="math-container">$O(n)$</span>, is easy. If by using functional they will probably get a <span class="math-container">$O(n^2)$</span> solution, and <span class="math-container">$O(n)$</span> is hard, then you are teaching a disadvantage on day one.)</p>
  <p>Fibonacci is, I think <span class="math-container">$O(2^n)$</span>, for simple recursive implementations.</p>
  <pre><code>fib 0 = 0
  fib 1 = 1
  fib n = fib (n-1) + fib (n-2)
  </code></pre>
  <p>I did it in <span class="math-container">$O(n)$</span> once, that was the day I learnt a lot about caching. It was hard, it took me a whole day.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-15T02:40:59.903Z
Answers.Text: Any suggestions on what math problems I could talk about?
Answers.UserDisplayName: Agnishom Chattopadhyay
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-15T08:04:14.517Z
Answers.Text: Added examples, counter example, and a link.
Answers.UserDisplayName: ctrl-alt-delor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-15T10:31:30.090Z
Answers.Text: On the other hand, if it's a demo rather than an exercise, a functional $O(n)$ Fibonacci can be just `fibhelper 0 a _ = a; fibhelper n a b = fib (n-1) b (a+b); fib n = fibhelper n 0 1`. (Although I suspect an idiomatic Haskell version would use a lazy infinite sequence and take the nth element).
Answers.UserDisplayName: Peter Taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-15T12:01:35.200Z
Answers.Text: @PeterTaylor very good. However you made an error: you call you called `fib` with 3 arguments. I changed it to `fibhelper`, tested it, thought it through and it worked. Fixed code `fibhelper 0 a _ = a; fibhelper n a b = fibhelper (n-1) b (a+b); fib n = fibhelper n 0 1`
Answers.UserDisplayName: ctrl-alt-delor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-20T16:47:05.277Z
Answers.Text: They are not at all too difficult if you are being guided and can evaluate code during the tutorial to follow along. Parsers in Haskell are amazingly elegant, but also have an air of practicality that can help keep novices interested. A really simple arithmetic expression parser *and* evaluator is just one line: `expr = "(" *> expr <**> ("+" $> (+) <|> "*" $> (*)) <*> expr <* ")" <|> decimal`. This also gives the opportunities to talk about some very useful Haskell operators and the importance of the little details in formal grammar definitions. 1 hour should be enough to cover 1 line of code.
Answers.UserDisplayName: Steven Armstrong
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-21T09:27:11.363Z
Answers.Text: @StevenArmstrong your comment seems more like an answer.
Answers.UserDisplayName: ctrl-alt-delor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-21T10:21:59.740Z
Answers.Text: Hmm, possibly, though it felt too simple at the time to qualify as an answer, I'll think about it and see if I can flesh it out into a proper one. The question did already consider an arithmetic expression evaluator so it did not feel like a useful answer.
Answers.UserDisplayName: Steven Armstrong
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-14T08:12:03.137Z
Answers.LastActivityDate: 2017-09-15T08:03:32.203Z
Answers.LastEditDate: 2020-06-18T08:36:57.023Z
Answers.UserDisplayName: ctrl-alt-delor
Body: <p>I am supposed to be holding a tutorial session in an Undergraduate Haskell Course, which is also supposed to be a first course in programming for a few of the students. Ideally, the tutorial should be interesting, interactive and inviting problem solving skills.</p>
  
  <p>My audience is a group of Undergraduate students, a large number of which are mathematically oriented and a few graduate students, majoring in Computer Science. For the undergraduate students, it can be assumed that quite a few of them are new to programming or CS in general. And functional programming is new to almost everyone. This tutorial is part of a course they are all attending - the aim of which is to introduce programming.</p>
  
  <p>I am wondering what sort of things I could cover in such a tutorial. Some ideas I had are these:</p>
  
  <ul>
  <li>A sudoku solver</li>
  <li>A Brain**** Interpretter</li>
  <li>An Arithmetic Expression Parser and Interpretter</li>
  <li>Discussing a data structure which the students have not seen before - like binomial heaps, or red black trees</li>
  </ul>
  
  <p>What other things could I try? Functional Programming specific applications are especially welcome.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-13T04:25:20.037Z
Comments.Text: Go with the sudoku solver man. Easy to explain and easy to implement as well. and welcome to the site because, you know, you are here :P
Comments.UserDisplayName: Jay
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-13T05:44:20.187Z
Comments.Text: Well, idk if I have a project idea for you, but based on your updated description, I think you can immediately reject your last three ideas. If most of your audience is new to programming, I don't think they'll either appreciate, care, or have the background to understand those three mini-projects. I would also recommend not approaching this from the perspective of "how can I introduce these students to Haskell/functional programming" -- I'd approach it from the perspective of "how can I introduce these students to programming" and ignore the people who are already familiar with CS.
Comments.UserDisplayName: Michael0x2a
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-13T11:44:54.273Z
Comments.Text: wait, a f word is allowed in a question?
Comments.UserDisplayName: Jay
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-13T11:53:40.750Z
Comments.Text: Welcome to [cseducators.se]!  Not an answer, but all of those projects strike me as very ambitious for a novice programmer, though if they're not programming it (it's merely a demonstration), then have at it.
Comments.UserDisplayName: Ben I.
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-14T14:48:06.620Z
Comments.Text: If you can't tackle the problems in 10 minutes yourself, don't expect beginners to do so in 1 hour.
Comments.UserDisplayName: Michel Billaud
Tags: <lesson-ideas><project><functional-programming>
Title: Mini-Projects that can be covered in an 1 hour Haskell tutorial
ThreadText: # Mini-Projects that can be covered in an 1 hour Haskell tutorial
  
  (Asked by: username_0 on 2017-09-13)
  
  I am supposed to be holding a tutorial session in an Undergraduate Haskell Course, which is also supposed to be a first course in programming for a few of the students. Ideally, the tutorial should be interesting, interactive and inviting problem solving skills.
  
  My audience is a group of Undergraduate students, a large number of which are mathematically oriented and a few graduate students, majoring in Computer Science. For the undergraduate students, it can be assumed that quite a few of them are new to programming or CS in general. And functional programming is new to almost everyone. This tutorial is part of a course they are all attending - the aim of which is to introduce programming.
  
  I am wondering what sort of things I could cover in such a tutorial. Some ideas I had are these:
  
  * A sudoku solver
  * A Brain\*\*\*\* Interpretter
  * An Arithmetic Expression Parser and Interpretter
  * Discussing a data structure which the students have not seen before - like binomial heaps, or red black trees
  
  What other things could I try? Functional Programming specific applications are especially welcome.
  
  **Tags:** lesson-ideas, project, functional-programming
  
  > **Comments:**
  > **username_1**: Go with the sudoku solver man. Easy to explain and easy to implement as well. and welcome to the site because, you know, you are here :P  
  > **username_2**: Well, idk if I have a project idea for you, but based on your updated description, I think you can immediately reject your last three ideas. If most of your audience is new to programming, I don't think they'll either appreciate, care, or have the background to understand those three mini-projects. I would also recommend not approaching this from the perspective of "how can I introduce these students to Haskell/functional programming" -- I'd approach it from the perspective of "how can I introduce these students to programming" and ignore the people who are already familiar with CS.  
  > **username_1**: wait, a f word is allowed in a question?  
  > **username_3**: Welcome to [cseducators.se]!  Not an answer, but all of those projects strike me as very ambitious for a novice programmer, though if they're not programming it (it's merely a demonstration), then have at it.  
  > **username_4**: If you can't tackle the problems in 10 minutes yourself, don't expect beginners to do so in 1 hour.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_6 on 2017-09-14. Score: 6
  
  # The ideas in your question are far too difficult, for a one hour introduction.
  
  Yesterday I had a look at Haskell and learnt some. I have over 30 years programming experience (20 years professional). Have experience with functional programming. Yet it took me several hours, and did not get far enough to be able to do your suggestions.
  
  # Mathematics
  
  You say that your students have a maths background.
  
  Take advantage of this. Choose some math problems. That Haskell is ideally suited to solve. And explain why you are doing this.
  
  Ensure that you have more than you think you will need, as some students will be much faster than you expect, but don't expect to use them all.
  
  There are some good ideas here <https://stackoverflow.com/a/15110828/537980> also some of the other answers, to the same question: sort, search, interpreter (this one may take too long), factorial.
  
  # Avoid bad examples
  
  Don't do problems that are more difficult in a functional language than in a procedural one (Reversing a list, using procedural techniques, in $O(n)$, is easy. If by using functional they will probably get a $O(n^2)$ solution, and $O(n)$ is hard, then you are teaching a disadvantage on day one.)
  
  Fibonacci is, I think $O(2^n)$, for simple recursive implementations.
  
  ```
  fib 0 = 0
  fib 1 = 1
  fib n = fib (n-1) + fib (n-2)
  
  ```
  
  I did it in $O(n)$ once, that was the day I learnt a lot about caching. It was hard, it took me a whole day.
  
  > **Comments:**
  > **username_0**: Any suggestions on what math problems I could talk about?  
  > **username_6**: Added examples, counter example, and a link.  
  > **username_7**: On the other hand, if it's a demo rather than an exercise, a functional $O(n)$ Fibonacci can be just `fibhelper 0 a _ = a; fibhelper n a b = fib (n-1) b (a+b); fib n = fibhelper n 0 1`. (Although I suspect an idiomatic Haskell version would use a lazy infinite sequence and take the nth element).  
  > **username_6**: @username_7 very good. However you made an error: you call you called `fib` with 3 arguments. I changed it to `fibhelper`, tested it, thought it through and it worked. Fixed code `fibhelper 0 a _ = a; fibhelper n a b = fibhelper (n-1) b (a+b); fib n = fibhelper n 0 1`  
  > **username_8**: They are not at all too difficult if you are being guided and can evaluate code during the tutorial to follow along. Parsers in Haskell are amazingly elegant, but also have an air of practicality that can help keep novices interested. A really simple arithmetic expression parser *and* evaluator is just one line: `expr = "(" *> expr <**> ("+" $> (+) <|> "*" $> (*)) <*> expr <* ")" <|> decimal`. This also gives the opportunities to talk about some very useful Haskell operators and the importance of the little details in formal grammar definitions. 1 hour should be enough to cover 1 line of code.  
  > **username_6**: @username_8 your comment seems more like an answer.  
  > **username_8**: Hmm, possibly, though it felt too simple at the time to qualify as an answer, I'll think about it and see if I can flesh it out into a proper one. The question did already consider an arithmetic expression evaluator so it did not feel like a useful answer.  
  
  ---
  
  ### Answer by username_5 on 2023-01-13. Score: 1
  
  You want an approach that aligns to the problems typed functional programming languages like Haskell lend themselves well to. That is to say, Category Theory + Tensor data. So the best problems to solve would likely be those involving linear algebra.
  
  Example:
  
  * Start with implementing scalar arithmetic (custom types and functions and all. Intro to Monads / Maybe for NaNs and such)(1 hour)
  * next ask them to build on the last example but implement vectors (again, all custom types, higher order functions)(1 hour)
  * next ask them to do the same but with Matrix (Kernels, Images, custom types, higher order functions)(1 hour)
  * next ask them to do the same but a linear solver (so det, eigenvectors and values)(1 hour)
  * finally ask them implement Principal Components Analysis (so learn about files and loading data)(1 hour)
  * leave them with a question at the end to further build off the work:
    + What is the principal component of a tensor? (if they coded things right, they'll have a joy of exploration )
    + How would you implement formulas and derivative functions? (abstract a part of the linear solver from before)
    + How would you implement graphs and graphing algorithms? (matrix implementation vs association list)
    + How would you rewrite the library for Tensors of infinite size, or how would you implement dynamic programming problems? (intro to functional reactive streams)
  
  
  ---
  
  