Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Win95 is not a virus; a virus does something. -- unknown source


programming / comp.lang.haskell / Re: Newbie needing help

SubjectAuthor
* Newbie needing helpSteve Graham
`* Re: Newbie needing helpBen Bacarisse
 `- Re: Newbie needing helpSteve Graham

1
Subject: Newbie needing help
From: Steve Graham
Newsgroups: comp.lang.haskell
Date: Sat, 14 Dec 2019 01:14 UTC
X-Received: by 2002:a0c:84a4:: with SMTP id m33mr16094991qva.40.1576286061646;
Fri, 13 Dec 2019 17:14:21 -0800 (PST)
X-Received: by 2002:a9d:1d02:: with SMTP id m2mr16734270otm.45.1576286061365;
Fri, 13 Dec 2019 17:14:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!peer02.am4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!82.197.223.106.MISMATCH!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!g89no835796qtd.0!news-out.google.com!w29ni1296qtc.0!nntp.google.com!g89no835789qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.haskell
Date: Fri, 13 Dec 2019 17:14:21 -0800 (PST)
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2601:601:9180:b9f0:116d:fc32:b4c0:fd87;
posting-account=lMndggoAAACR6bdLBlBjeKrA4qihooHu
NNTP-Posting-Host: 2601:601:9180:b9f0:116d:fc32:b4c0:fd87
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <addc4555-3194-40ec-9df7-73720b0a40a8@googlegroups.com>
Subject: Newbie needing help
From: solitary...@gmail.com (Steve Graham)
Injection-Date: Sat, 14 Dec 2019 01:14:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2357
X-Received-Body-CRC: 2486012532
View all headers
Long-time programmer/newbie with Haskell...

Thought I'd check out a program I saw at https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
take 20 (pdiv [1] [-1,-1])
take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

I entered at the Haskell Online Compiler https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell and on my iOS Haskell app and got the same error:

[1 of 1] Compiling Main             ( Main.hs, Main.o )

Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

Interestingly on my Windows 10 GHCi app, it worked fine:

GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
Prelude> take 20 (pdiv [1] [-1,-1])
[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765]
Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])
[0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519]
Prelude>

I'm sure it's some formatting issue.  I would appreciate any assistance you folks could offer.

Thanks, Steve



Subject: Re: Newbie needing help
From: Ben Bacarisse
Newsgroups: comp.lang.haskell
Organization: A noiseless patient Spider
Date: Sat, 14 Dec 2019 02:07 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.haskell
Subject: Re: Newbie needing help
Date: Sat, 14 Dec 2019 02:07:16 +0000
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <87o8wby817.fsf@bsb.me.uk>
References: <addc4555-3194-40ec-9df7-73720b0a40a8@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d95355d5686ef8d3fe72a512bc5e294e";
logging-data="3845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gfglAotpzZ3Wrl87kp3B/myrnCEj6tZg="
Cancel-Lock: sha1:+dd04qj8fBqUs3nO145PpAgAd5E=
sha1:SB1Z6oCbR+7LKG6KzyYkpyg7BzU=
X-BSB-Auth: 1.7441b7185b667757e267.20191214020716GMT.87o8wby817.fsf@bsb.me.uk
View all headers
Steve Graham <solitary.wanderer52@gmail.com> writes:

Long-time programmer/newbie with Haskell...

Thought I'd check out a program I saw at
https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
take 20 (pdiv [1] [-1,-1])
take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

I entered at the Haskell Online Compiler
https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell
and on my iOS Haskell app and got the same error:

[1 of 1] Compiling Main             ( Main.hs, Main.o )

Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

Interestingly on my Windows 10 GHCi app, it worked fine:

GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
Prelude> take 20 (pdiv [1] [-1,-1])
[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765]
Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])
[0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519]
Prelude>

I'm sure it's some formatting issue.  I would appreciate any
assistance you folks could offer.

It's not a formatting issue.  The interpreter will take expressions and
evaluate them, but a Haskell program, suitable for compilation, can't
have "top-level" expressions.

The compilable, "program" version of what you wrote is

pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t

main = do
  print $ take 20 (pdiv [1] [-1,-1])
  print $ take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

You would see the same error if you used ghc (rather than ghci) on your
Windows box:

$ ghc p.hs
[1 of 1] Compiling Main             ( p.hs, p.o )

p.hs:2:1: error:
    Parse error: module header, import declaration
    or top-level declaration expected.
  |
2 | take 20 (pdiv [1] [-1,-1])
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^

--
Ben.


Subject: Re: Newbie needing help
From: Steve Graham
Newsgroups: comp.lang.haskell
Date: Sat, 14 Dec 2019 02:12 UTC
References: 1 2
X-Received: by 2002:a05:620a:a5c:: with SMTP id j28mr16545389qka.218.1576289533432;
Fri, 13 Dec 2019 18:12:13 -0800 (PST)
X-Received: by 2002:aca:c493:: with SMTP id u141mr7311023oif.62.1576289533036;
Fri, 13 Dec 2019 18:12:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no961523qtd.0!news-out.google.com!w29ni1306qtc.0!nntp.google.com!g89no961516qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.haskell
Date: Fri, 13 Dec 2019 18:12:12 -0800 (PST)
In-Reply-To: <87o8wby817.fsf@bsb.me.uk>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=2601:601:9180:b9f0:116d:fc32:b4c0:fd87;
posting-account=lMndggoAAACR6bdLBlBjeKrA4qihooHu
NNTP-Posting-Host: 2601:601:9180:b9f0:116d:fc32:b4c0:fd87
References: <addc4555-3194-40ec-9df7-73720b0a40a8@googlegroups.com> <87o8wby817.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3c11dc7a-fb9e-4714-81de-abb9424b6c33@googlegroups.com>
Subject: Re: Newbie needing help
From: solitary...@gmail.com (Steve Graham)
Injection-Date: Sat, 14 Dec 2019 02:12:13 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
On Friday, December 13, 2019 at 6:07:18 PM UTC-8, Ben Bacarisse wrote:
Steve Graham <xxxx> writes:

Long-time programmer/newbie with Haskell...

Thought I'd check out a program I saw at
https://programmingpraxis.com/2019/12/13/pentabonacci-numbers/#comments:

pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
take 20 (pdiv [1] [-1,-1])
take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

I entered at the Haskell Online Compiler
https://paiza.io/projects/HEXouZ1jmJjemSO1cULHoA?language=haskell
and on my iOS Haskell app and got the same error:

[1 of 1] Compiling Main             ( Main.hs, Main.o )

Main.hs:3:1: error:
    Parse error: naked expression at top level
    Perhaps you intended to use TemplateHaskell

Interestingly on my Windows 10 GHCi app, it worked fine:

GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Prelude> pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t
Prelude> take 20 (pdiv [1] [-1,-1])
[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765]
Prelude> take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])
[0,1,1,2,4,8,16,31,61,120,236,464,912,1793,3525,6930,13624,26784,52656,103519]
Prelude>

I'm sure it's some formatting issue.  I would appreciate any
assistance you folks could offer.

It's not a formatting issue.  The interpreter will take expressions and
evaluate them, but a Haskell program, suitable for compilation, can't
have "top-level" expressions.

The compilable, "program" version of what you wrote is

pdiv (a:s) t = a : pdiv (zipWith (-) (s ++ repeat 0) (map (*a) t)) t

main = do
  print $ take 20 (pdiv [1] [-1,-1])
  print $ take 20 (pdiv [0,1] [-1,-1,-1,-1,-1])

You would see the same error if you used ghc (rather than ghci) on your
Windows box:

$ ghc p.hs
[1 of 1] Compiling Main             ( p.hs, p.o )

p.hs:2:1: error:
    Parse error: module header, import declaration
    or top-level declaration expected.
  |
2 | take 20 (pdiv [1] [-1,-1])
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^

--
Ben.

Thanks, Ben.  The default for a new iOS Haskell program is:

main = do
  putStr ""

Guess I should have realized that main = do was meant to be part of programs, at least some of them.

Steve


1
rocksolid light 0.7.2
clearneti2ptor