vytaute
vytaute

Reputation: 1480

First Haskell program not launching

I have written my first Haskell code in Visual Studio Code. I want to implement list of lists so I started with simple list.

module Main where
import System.Environment
import Data.List
import Data.Ord

main :: IO ()
main =  do
    let lostNumbers = [4,8,15,16,23,42]  

When I try to launch my program I get:

enter image description here

How do I declare a list of lists in Haskell? Or at least just a simple list?

EDIT: I have found topic that discuss on where to look for Haskell tutorials: Getting started with Haskell

Hope it will help someone

Upvotes: 1

Views: 109

Answers (3)

mohamad Jamal
mohamad Jamal

Reputation: 28

your code have unused imports as a starting point to write haskell code, I modified your code to

lostNumbers :: [Integer]
lostNumbers = [4,8,15,16,23,42]  

or, in case you would like to use module keyword, you have to be careful for spaces for example

module Main where
    lostNumbers :: [Integer]
    lostNumbers = [4,8,15,16,23,42]  

Upvotes: 0

Eloi Torrents
Eloi Torrents

Reputation: 33

When I compile your code, I get this error:

main.hs:8:5: error:
    The last statement in a 'do' block must be an expression
      let lostNumbers = [4, ....]

So the last statement of the do block must be an expression such as

print lostNumbers

Upvotes: 1

Holp
Holp

Reputation: 294

The error message tells you exactly what is wrong. The last line of your do block is that let expression and not a value of type IO ()

Update it to, for example:

lostNumbers = [4,8,15,16,23,42] 

main :: IO ()
main =  do
    print lostNumbers

If the let is important to you..

main :: IO ()
main =  do
    let lostNumbers = [4,8,15,16,23,42] in print lostNumbers

Upvotes: 2

Related Questions