Coder Social home page Coder Social logo

seanpm2001 / learn-haskell Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 266 KB

A repository for showcasing my knowledge of the Haskell programming language, and continuing to learn the language.

Home Page: https://github.com/seanpm2001/Learn/

License: GNU General Public License v3.0

Haskell 99.71% HTML 0.29%
collection education gpl3 gplv3 haskell haskell-language hs learn-haskell md seanpm2001

learn-haskell's Introduction


/HaskellLogoStyPreview-1.png

Learning Haskell

I am not too experienced with the Haskell programming language at the moment. This document will go over my knowledge of the Haskell language so far.

This document used versopm 2010 of the Haskell programming language. The version will be listed with each example.

The following examples are written in Haskell, and not Literate Haskell.

Comments in Haskell

Comments in Haskell are similar to languages lika Ada, Elm, Lua, MoonScript, etc. They are implemented like so:

-- This is a single line comment
-- As far as I know, Haskell does not support multi-line comments.

This example works with every version of Haskell.

Break keyword in Haskell

Haskell does NOT support the break keyword.

To this day, I am still not entirely sure what the break keyword does, but most languages support it.

Hello World in Haskell

A hello world program in Haskell is a bit more complicated than a Python or Perl Hello World program, but it isn't very difficult either. It is not similar to any language I am currently familiar with.

main = putStrLn "Hello World"

This example works with every version of Haskell.

/!\ This example has not been tested yet, and may not work

Without an interpreter, a Haskell Hello World program is written like this:

module Main (main) where

main :: IO ()
main = putStrLn "Hello World"

This example works with every version of Haskell.

Factorials in Haskell

Factorials are pre-defined in Haskell as a function. They are written like so:

Integral factorial
-- Normal, simple factorial
factorial :: (Integral a) => a -> a

This example works with every version of Haskell.

They can also be written in many other ways:

If then Else factorial
-- Using if, then, else statements
factorial n = if n < 2
              then 1
              else n * factorial (n - 1)

This example works with every version of Haskell.

Recursive factorial with pattern matching
-- Recursive factorial (using pattern matching)
factorial 0 = 1
factorial n = n * factorial (n - 1)

This example works with every version of Haskell.

Recursive factorial with guards
-- Recursive factorial (with guards)
factorial n
   | n < 2     = 1
   | otherwise = n * factorial (n - 1)

This example works with every version of Haskell.

Factorials using lists and the product keyword
-- Using lists, and the product keyword
factorial n = product [1..n]

This example works with every version of Haskell.

Folding factorials
-- Using the fold keyword
factorial n = foldl (*) 1 [1..n]

This example works with every version of Haskell.

Point free style factorial
-- Using a point free style
factorial = foldr (*) 1 . enumFromTo 1

This example works with every version of Haskell.

Source

The majority of my Haskell knowledge comes from self-experimentation, and Wikipedia. Self experimentation didn't go far, and unfortunately the majority of knowledge currently comes from Wikipedia. I wanted to make source code more original, but there isn't any other way I would have written it.

Other knowledge of Haskell

  1. Haskell is a curly bracket and semicolon language

  2. Haskell is a purely functional programming language

  3. Haskell uses the *.hs file extension

  4. A variant of Haskell exists known as Literate Haskell

  5. Literate Haskell uses the *.lhs file extension

  6. Haskell is a language recognized by GitHub

  7. Haskell is an open source programming language.

  8. Haskell has existed since the year 1990.

  9. No other knowledge of Haskell at the moment.


File version: 1 (2022, Tuesday, April 19th at 2:57 pm PST)


learn-haskell's People

Contributors

seanpm2001 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seanwallawalla

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.