28

Is there a Haskell interpreter (with standard libraries) that can be installed on Android?

So that someone with an Android device can do some Haskell exercises on an Android device: write and run some example code in Haskell.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
imz -- Ivan Zakharyaschev
  • 4,921
  • 6
  • 53
  • 104
  • 4
    Related: [Running a Haskell program on the Android OS](http://stackoverflow.com/q/5151858/94687). – imz -- Ivan Zakharyaschev Apr 29 '11 at 05:47
  • 5
    The ability to write and execute small snippets of code is essential for studying programming and for real programming/software developemnt. It's convenient to be able to test a small snippet of code in GHCi when you are thinking about something. This question asks whether this is possible if you have an Android device in your hands (and are writing/elaborating a Haskell program). How can this be offtopic? – imz -- Ivan Zakharyaschev May 28 '13 at 12:21
  • 2
    Since this year (2020) [you can run ghc and ghci on Termux](https://github.com/termux/termux-packages/issues/80#issuecomment-647120477). Install Termux app on your Android and then do: `pkg install unstable-repo; pkg install ghc` – erik Dec 17 '20 at 23:49
  • @erik one comment - ghci still unavailable :( – Ivan May 28 '21 at 11:36
  • 1
    Looks like ghc isn't available from that repository. – Dan Dart Sep 14 '21 at 15:16
  • 1
    The Replit app allows you to use GHCi and source files, and seems to fit the bill: https://replit.com/mobile-download – Jimmy Jun 08 '23 at 07:28

6 Answers6

8

Hugs is written in C and quite portable. It should be possible to port it to Android.

augustss
  • 22,884
  • 5
  • 56
  • 93
  • 2
    I just tried to compile it, and unfortunately it doesn't work: checking build system type... i686-pc-linux-gnu checking host system type... arm-unknown-linux-gnu checking target system type... arm-unknown-linux-gnu configure: error: Hugs98 does not yet support differing build/host (i.e., cross-compiling) – NoBugs Jan 18 '12 at 20:18
4

Taking a note from imz, all you need is

  • ConnectBot or similar
  • A remote machine with
    • Vim, Emacs, or similar
    • runghc / ghci / hugs / yourfavoritehaskellinterpreterorcompiler

It's not as solid as a dedicated app or scripting layer would be, but honestly, for your use cases, it would provide almost exactly the same functionality as those options (if not more). And it would be just as "mobile" as a website (depends only on the uptime of the host and the connectivity of the client).

Dan Burton
  • 53,238
  • 27
  • 117
  • 198
  • 1
    This seems like the way forward for working with Haskell code non-x86 platforms. Hopefully someone will come along with a use-case and $$$ to provide a full featured ARM runtime for Haskell. – zmanian Apr 29 '11 at 17:35
  • 4
    This is *not* a solution, since it by definition is not *on* Android. You can’t just run Crysis on a supercomputer, stream the video and input to/from your phone, and say your phone “runs” Crysis! – Evi1M4chine Mar 04 '14 at 22:21
3

You can use tryhaskell.org from your mobile browser. It will accept any valid expression, but keep in mind that defining your own data types won't be possible.

Jason Dagit
  • 13,684
  • 8
  • 33
  • 56
  • But what if I'd like to supply some my own source code with definitions (incl. type definitions), and interpret some more expressions with the use of it. – imz -- Ivan Zakharyaschev Apr 29 '11 at 04:49
  • 1
    So, perhaps, SSHing to a machine with GHC or Hugs would be a possible practical solution (though not mobile at all). – imz -- Ivan Zakharyaschev Apr 29 '11 at 04:56
  • 1
    Looks like tryhaskell.org utilizes a JSON based API. This means it might be possible to replicate this functionality in a more mobile friendly, native interface, though it would still only be for oneliners and still require an internet connection to complete. Essentially, reimplement the relevant parts of http://tryhaskell.org/js/tryhaskell.js in Java and wrap it in a GUI – Alex Hart Sep 19 '12 at 04:37
  • @AlexHart This idea seems to have been implemented by Bram Neijt in "Try Haskell" app -- https://play.google.com/store/apps/details?id=nl.bneijt.tryhaskell ! It's of 2012, July 22 (even earlier than your comment :) ) Not sure whether it's open-source, will study his website to find out this -- http://bneijt.nl/ . – imz -- Ivan Zakharyaschev Jun 01 '13 at 08:03
  • Yes, that app is open-source (GPLv3): https://github.com/bneijt/tryhaskell . – imz -- Ivan Zakharyaschev Jun 01 '13 at 08:13
  • @AlexHart Another one: "Learn Haskell" -- https://play.google.com/store/apps/details?id=hu.dreamland_swh.learnhaskell , of 2013, February 19. Don't know whether it's open-source. – imz -- Ivan Zakharyaschev Jun 01 '13 at 09:10
3

For some negative information, all the work I've seen for GHC on Android (such as http://ipwnstudios.com/) is based on cross-compilation, rather than building GHC for android or ARM.

Brandon
  • 355
  • 2
  • 7
1

I just found IDEone in the Android Market, which sends your code to an online service. It works, but programming on Android isn't much fun. Btw: In case you don't want to register see BugMeNot

Gerold Meisinger
  • 4,500
  • 5
  • 26
  • 33
0

Surprisingly, I couldn't uncover any existing Haskell interpreter for Android.

But here are some instructions for writing your own interpreter for the Scripting Layer on Android. That's assuming you're willing to try mapping the haskell functions on top of the Java android ones (which is not a perfect solution, I know). You'll also want to refer to their scripting layer written for Scala, because that's the one that comes closest to Haskell (which is not very close I admit).

Otherwise, there shouldn't be any reason why any of those Haskell implementations couldn't be directly compiled for Android using the NDK. As long as they're written in C, they should work on Android. For C++, that's a little bit more tricky since Android doesn't have all the C++ headers.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • 1
    yep lots of interpreted languages have been ported but I don't think anyone has gotten around to haskell yet. I don't imagine it would be to terribly difficult to do though I have been wanting to give it a shot but haven't found the time. – Nathan Schwermann Apr 29 '11 at 04:52