1

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

vytaute
  • 1,260
  • 4
  • 16
  • 36

3 Answers3

2

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
Holp
  • 283
  • 1
  • 5
  • Thank you, it helped. I am new. It is very hard to find any good tutorials about Haskell. Not even how to declare an array, I couldnt find it anywhere. Is it dead language, or I was looking in wrong places or what? :) – vytaute Mar 28 '21 at 15:51
  • 2
    There are excellent books for learning Haskell. For example https://haskellbook.com/ – Holp Mar 28 '21 at 15:53
  • 3
    [Learn You a Haskell](http://learnyouahaskell.com/) is by far the best for a Haskell beginner in my opinion. There's also the excellent [wikibook](https://en.wikibooks.org/wiki/Haskell) – Robin Zigmond Mar 28 '21 at 15:54
  • haskellbook.com is paid, but there are 95 pages for free so thanks :) – vytaute Mar 28 '21 at 15:55
  • Learn You a Haskell sure does cater more to beginner sensibilities. I'm not sure it's a better book for beginners than Haskell Book though. – Holp Mar 28 '21 at 15:56
1

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
0

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]