Question

Excuse the simplicity of this question, but I didn't find another question that addressed my issue. I have installed haskell and leksah, then performed "cabal install nat" to install the natural numbers lib. The lib looks like it was installed in "/Users/jstanford/Library/Haskell/ghc-7.0.4/lib/nat-0.2/lib"

I created a workspace and a package in leksah, and updated my prefs to look in:

/Library/Frameworks/GHC.framework /Users/jstanford/Library/Haskell /Users/jstanford/.leksah-0.10/packageSources

for package sources and left the default ~/.leksah-0.10/packageSources for unpacking cabal packages.

I grabbed the first snippets of code from "Pearls of Functional Algorithm Design", so my code looks like this:

-----------------------------------------------------------------------------
--
-- Module      :  Main
-- Copyright   :
-- License     :  AllRightsReserved
--
-- Maintainer  :
-- Stability   :
-- Portability :
--
-- |
--
-----------------------------------------------------------------------------

module Main (
    main
) where

import Data.List ((\\))
import GHC.Arr (accumArray, elems, Array(..))



minfree :: [Nat] -> Nat
minfree xs = head([0 ..])\\ xs

search :: Array Int Bool -> Int
search = length takeWhile id . elems

checklist :: [Int] -> Array Int Bool
checklist xs = accumArray(V) False (0,n)
               (zip (filter (<= n) xs) (repeat True))
               where n = length xs

main = (

    minfree[0, 2, 5]
    )

Leksah was able to find the imports for \ and Array, but can't find Nat. Any pointers on how to find the import? The compiler also complains about accumArray(V). I suspect that V is not really supposed to be the capital letter V, rather some symbol that looks like a V. Guidance on that would be very much appreciated as well!

Était-ce utile?

La solution

The Nat type is defined in Data.Number.Nat, so you should import it at the top of your file:

import Data.Number.Nat

As for the (V), it's probably meant to be (||). The "V" is most likely ∨, the symbol for logical disjunction: more commonly known as the boolean or operator. Operator substitutions like this are common in typeset Haskell code, but can be quite confusing until you get used to seeing them.

Additionally, you shouldn't import the array functions from GHC.Arr; that's an internal GHC module; I recommend importing Data.Array instead.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top