Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell : "The last statement in a 'do' construct must be an expression"

Tags:

haskell

I'm going through the book Natural Language Processing for Working Programmers. The book uses Haskell, which I don't have much experience with. The code below throws an error in GHCI

:{
do
  l <- [0..9]
  ps <- (\x -> [x-1, x+2]) l
  return ps
:}

This is the error message returned

The last statement in a 'do' construct must be an expression

All answers I've come across seem to suggest it is an indentation error, but as far as I can tell the indentation seems correct. Any ideas what the problem could be?

like image 539
Okal Otieno Avatar asked Dec 29 '11 05:12

Okal Otieno


1 Answers

I typed your code into ghci 7.0.3 and did not get an error.

Prelude> :{
Prelude| do
Prelude|   l <- [0..9]
Prelude|   ps <- (\x -> [x-1, x+2]) l
Prelude|   return ps
Prelude| :}
[-1,2,0,3,1,4,2,5,3,6,4,7,5,8,6,9,7,10,8,11]

Edit: When I use ghci 6.12.1 as packaged in Ubuntu 10.04, I get the same error as you.

like image 58
dave4420 Avatar answered Sep 23 '22 20:09

dave4420