Coder Social home page Coder Social logo

octavipascual / cis194-introductiontohaskell Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 6.0 3.36 MB

🚀Solutions of CIS 194: Introduction to Haskell (Spring 2013) course

Home Page: http://www.seas.upenn.edu/~cis194/spring13/

License: MIT License

Haskell 100.00%
cis194 haskell-learning functional-programming

cis194-introductiontohaskell's Introduction

CIS 194: Introduction to Haskell (Spring 2013)

In order to learn Haskell I took the CIS 194: Introduction to Haskell (Spring 2013) course.

This repository contains the solutions of each assignment of the course.

Apart from the material of the course, I also checked the following materials:

In addition, since I took the course in an autonomous way, I used some resources to check whether my solutions were correct or not. I always try to solve the problems on my own and I only may take a look if I am really stuck with an exercise. However, when I have already solved the whole assignment, I like to see in detail how others solved it and that makes me learn a lot!

Finally, I tried to explain how I solved each exercise of the homework to remember how I came to the final solution. Moreover, it may also help the reader to understand the reasoning behind each solution.

cis194-introductiontohaskell's People

Contributors

octavipascual avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cis194-introductiontohaskell's Issues

A testcase make myFoldl in homework4 fail

Hi,
I find a testcase that make the myFoldl function fail.

(foldr . flip) (++) "A" ["B","C","D"]    -- outputs "ADCB", rather than "ABCD"

What's wrong is after flipping the reduction function, the arguments are swapped, but the order of application is still from right to left.

More explicit,

(foldr . flip) f x0 [x1, x2, x3, x4, x5, ... , xn]
= (f ( ... (f (f x0 xn) xn-1) ... ) x1)

while

foldl f x x0 [x1, x2, x3, x4, x5, ... , xn]
= (f ( ... (f (f x0 x1) x2) ... ) xn)

Incorrect nextLevel function from homework 8

Hi!

Probably I'm a bit late to the Party 😀, but after I've finished the homework, I've decided to take a look at what others have come up with and found your solution. You did a great job with explanations, but the problem is that nextLevel function, even though elegant, doesn't return a correct result.

You version computes the following GuestList if you give it testCompany:

GL [Emp {empName = "Bob", empFun = 2},Emp {empName = "John", empFun = 1},Emp {empName = "Sue", empFun = 5},Emp {empName = "Sarah", empFun = 17}] 25

However, the maximised one is:

GL [Emp {empName = "John", empFun = 1},Emp {empName = "Sue", empFun = 5},Emp {empName = "Fred", empFun = 3},Emp {empName = "Sarah", empFun = 17}] 26

The problem is that you don't check combinations of lists with and without bosses residing in different subtrees, so simply doing mconcat on with and without boss subtrees is not optimal.

I came up with the following solution which gives the right answer:

nextLevel :: Employee -> [(GuestList, GuestList)] -> (GuestList, GuestList)
nextLevel emp xs = (snd best, fst best)
  where best = glCons emp <$> bestSublists
        bestSublists = foldr (\(l, r) (vl, vr) 
                        -> (moreFun (l <> vr) . moreFun (l<>vl) $ r <> vl, r <> vr)) mempty xs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.