FP Cvičení 1

From Marek Běhálek Wiki
Revision as of 08:01, 6 September 2019 by Beh01 (talk | contribs) (Created page with "*Spusťte <code>ghci</code> z příkazové řádky. Bude spuštěn interpret GHC, výstup by měl vypadat nějak takto:")
Jump to navigation Jump to search

Pracovní prostředí

Připravte si pracovní prostředí s využitím návodu ze stránek Funkcionální programování.

Jak ověřit, že to funguje?

  • Spusťte ghci z příkazové řádky. Bude spuštěn interpret GHC, výstup by měl vypadat nějak takto:
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude>
  • If you write expression, for example 1+2*3, it should be evaluated. You can close this interpreter by typing :q.
  • Open Visual Studio Code, create a file simple.hs and put there following lines of code:
doubleMe x = x * x

plus x y  = x + y + 'a'

It should report a problem in function plus (you can not use + with letter, it can be repaired by removing + 'a'). Report from VS Code is refreshed whenever the source file is saved on disk.

First program in Haskell

In your favorite development environment (VS Code by default):

  • Crate a file simple.hs.
  • Create a function pythagoras a b that computes c based on . Necessary functions can be found: Hoogle
  • Open ghci and run the implemented function with 3 4. File can be loaded using command :l (:load) and reloaded with :r (:reload).

Real first program in Haskell

If you are complaining, that all programming courses should start with printing "Hello world!" on the screen and that is why previous task sucks. Do the following exercise.

  • Crate a file firstProgram.hs with following content:
main = do putStr "Hello world!"
  • Compile it with 'GHC compiler' (command ghc).
  • It should produce an executable file firstProgram(.exe), run this file.