News aggregator

OcaPic: Programming PIC microcontrollers in OCaml

Lambda the Ultimate - Fri, 08/21/2015 - 12:33am

Most embedded systems development is done in C. It's rare to see a functional programming language target any kind of microcontroller, let alone an 8-bit microcontroller with only a few kB of RAM. But the team behind the OcaPic project has somehow managed to get OCaml running on a PIC18 microcontroller. To do so, they created an efficient OCaml virtual machine in PIC assembler (~4kB of program memory), and utilized some clever techniques to postprocess the compiled bytecode to reduce heap usage, eliminate unused closures, reduce indirections, and compress the bytecode representation. Even if you're not interested in embedded systems, you may find some interesting ideas there for reducing overheads or dealing with constrained resource budgets.

Categories: Offsite Discussion

A general data-type construction function

Haskell on Reddit - Thu, 08/20/2015 - 10:45pm

Hey guys, I've just had a simple idea of the general construction interface for data-types using a typeclass. Please see the following GHCi session:

$ ghci -XNoImplicitPrelude GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help > import BasePrelude BasePrelude> :set -XFlexibleInstances BasePrelude> :{ BasePrelude| class Constructor a where BasePrelude| construct :: a BasePrelude| BasePrelude| instance Constructor (a -> b -> (a, b)) where BasePrelude| construct = (,) BasePrelude| BasePrelude| instance Constructor (a -> b -> c -> (a, b, c)) where BasePrelude| construct = (,,) BasePrelude| BasePrelude| BasePrelude| data T3 a b c = T3 a b c deriving (Show) BasePrelude| BasePrelude| instance Constructor (a -> b -> c -> T3 a b c) where BasePrelude| construct = T3 BasePrelude| :} BasePrelude> construct 'a' 'b' 'c' :: (Char, Char, Char) ('a','b','c') BasePrelude> construct 'a' 'b' 'c' :: T3 Char Char Char T3 'a' 'b' 'c' BasePrelude> construct <$> pure 'a' <*> pure 'b' <*> pure 'c' :: Maybe (Char, Char, Char) Just ('a','b','c')

Things to notice: the Constructor instance gets determined by the result type, so it may be inferred from your outer function signature or you'll have to specify it yourself as I do in the session above. The typeclass is identical to Default, so it may be used instead.

Let's discuss whether the thing is viable and needs releasing.

submitted by nikita-volkov
[link] [13 comments]
Categories: Incoming News

ANN: cabal-bounds 1.0.0

haskell-cafe - Thu, 08/20/2015 - 10:23pm
cabal-bounds[1] is a command line programm for managing the bounds/versions of the dependencies in a cabal file. Changes for 1.0.0 ================= * automatically find the cabal and setup-config files * ignore the base library by default Perhaps the two most relevant use cases: Initialize Bounds ================= If you have started a new project, created a cabal file, added dependencies to it, build it, and now want to set the lower and upper bounds of the dependencies according to the currently used versions of the build, then you can just call: $> cabal-bounds update This call will update the bounds of the dependencies of the cabal file in the working directory. Raise the Upper Bounds ====================== If you have several cabalized projects, then it can be quite time consuming to keep the bounds of your dependencies up to date. Especially if you're following the [package versioning policy](<http://www.haskell.org/haskellwiki/Package_versioning_policy>), then you want to raise your upp
Categories: Offsite Discussion

WTH is up with the Numeric type??

Haskell on Reddit - Thu, 08/20/2015 - 10:12pm

EDIT: THe question is meant to read

WTH is up with the Natural type??

For those of you who don't know (I didn't know until about a week ago), Haskell has a new (since base 4.8) unbounded, unsigned integral number type called Natural, where Natural is to Word as Integer is to Int: https://hackage.haskell.org/package/base/docs/Numeric-Natural.html

As you can see from the link, it has been placed in its own brand spanking new module, Numeric.Natural.

Why is it in its own module, and why the funny name?

I guess the answer to the first question is "Because of all the type astronauts creating their own Nat(ural) types while trying to add dependent types to Haskell." I think the module name is bizarre, though.

What gives?

submitted by BoteboTsebo
[link] [15 comments]
Categories: Incoming News

octree implementation - followup to "How to modelouter space for a MUD"

haskell-cafe - Thu, 08/20/2015 - 9:30pm
It looks like Octree is what I want if I can solve a particular problem. First let me articulate what I am looking for. (1) Objects in 3-d space with no spatial extent. Collision is determined by two objects occupying the same point.' (2) Efficient insert-delete-update #2 seems to be the problem. I found this library, thankfully. I believe it's exactly what I am looking for, but for quadtrees. https://github.com/AshleyMoni/QuadTree I'm a little overwhelmed as this is a new data structure for me. I believe if I can grok what is going on in this library, I can take these ideas and extend them to the octree. I'm referring specifically to this module https://github.com/AshleyMoni/QuadTree/blob/master/Data/QuadTree/Internal.hs And these functions setLocation :: Eq a => Location -> a -> QuadTree a -> QuadTree a setLocation = set . atLocation atLocation (Having difficulty cutting and pasting this to mail.) I'd like to be able to visualize how the tree is being compressed, it may help to be able to see wha
Categories: Offsite Discussion

how to do invertible type families?

Haskell on Reddit - Thu, 08/20/2015 - 3:55pm

Back in the days of fundeps we could define a type class that gives us an invertible type function, e.g.: class Foo a b | a -> b, b -> a. These days we can use type families to implement each direction of that invertible type function, but this runs into coherence issues during type inference, because just using type families looses track of the fact that the two families are related. Is there any way to state —once and for all— that a ~ Foo (UnFoo a) and b ~ UnFoo (Foo b) hold for all types?

submitted by winterkoninkje
[link] [5 comments]
Categories: Incoming News

ANN: cabal-bounds 1.0.0

Haskell on Reddit - Thu, 08/20/2015 - 3:24pm

cabal-bounds[1] is a command line programm for managing the bounds/versions of the dependencies in a cabal file.

Changes for 1.0.0
  • automatically find the cabal and setup-config files
  • ignore the base library by default

Perhaps the two most relevant use cases:

Initialize Bounds

If you have started a new project, created a cabal file, added dependencies to it, build it, and now want to set the lower and upper bounds of the dependencies according to the currently used versions of the build, then you can just call:

$> cabal-bounds update

This call will update the bounds of the dependencies of the cabal file in the working directory.

Raise the Upper Bounds

If you have several cabalized projects, then it can be quite time consuming to keep the bounds of your dependencies up to date. Especially if you're following the package versioning policy, then you want to raise your upper bounds from time to time, to allow the building with newer versions of the dependencies.

cabal-bounds tries to automate this update process to some degree. So a typical update process might look like:

# update the version infos of all libraries $> cabal update # drops the upper bound of all dependencies of the cabal file in the working directory $> cabal-bounds drop --upper # create a cabal sandbox for building your project, this ensures that you're really using # the newest available versions of the dependencies, otherwise you would be constraint # to the already installed versions $> cabal sandbox init # build your project $> cabal install # update the upper bound of all dependencies of the cabal file in the working directory $> cabal-bounds update --upper

Please consult the README for further informations.

[1] https://github.com/dan-t/cabal-bounds

submitted by dan00
[link] [9 comments]
Categories: Incoming News

How to build API wrapper client in Haskell (best practice ) ?

Haskell on Reddit - Thu, 08/20/2015 - 2:05pm

Hi there

I am planning to write a small API REST client using Haskell. It will allow user to authenticate, make some search in the database, and do some updates to his profile. So I was wondering if there any suggestions, tutorials, best practices, architecture, patterns in terms of approaching these problems ?

Any suggestions and links are welcome !

thanks in advance

submitted by raw909
[link] [6 comments]
Categories: Incoming News

An implementation of the board game Diplomacy

Haskell on Reddit - Thu, 08/20/2015 - 12:51pm

Announcing the diplomacy library and server.

If you like to play Diplomacy face-to-face, try using this server! Each player can participate using their own smartphone or laptop.

submitted by alexvieth
[link] [11 comments]
Categories: Incoming News

How to accomplish edits of a large dataset in Haskell

Haskell on Reddit - Thu, 08/20/2015 - 12:01pm

I have a pet project of making a little MUD (Multi User Dungeon) with Haskell to learn the language better. I currently have a Haskell function that will dig out a 'dungeon' area and hold information about each of the rooms with the connections between them. I even have some separated-out IO functions to save/load them! Neat.

So here's the tricky part I can't wrap my head around. What I want to do is allow the user to load up a 'dungeon', then traverse to each room. Ok, not hard. But I want them to be able to edit the description of the room. I obviously can't just edit the description 'field' of the room, as everything's immutable.

Currently my structure is that I have a list of Room data types that include description as part of their definition. I also have a list of Connection data types that contain references to two rooms, one for either end. So if I alter a Room, it feels like I have to recreate the Room and Connection lists, and both are going to be a pain! There has to be a better way of doing this.

Of course, I could just manually edit the file's saved descriptions, but that's not the point of learning functional programming. ;)

Any advice/ideas appreciated!

submitted by nevertras
[link] [4 comments]
Categories: Incoming News

Help with Understanding the Output of Haskell Program Coverage

Haskell on Reddit - Thu, 08/20/2015 - 11:58am

Hi Everyone,

I wanted to learn about my test coverage and learned from the Haskell Wiki about the hpc tool. Since I am using stack, I was able to do stack test --coverage to get a test coverage report, which is nice.

I do have a few questions in understanding these reports and how to improve my test coverage. I am happy to update the Wiki based on the responses I get here.

I am looking at the generated HPC html file and the questions I have are:

  1. How do I exclude some files from hpc report when using stack? If I cannot, do I have to run the hpc tool manually with the exclude flag? Should the binary generated by stack be used for this?

  2. What are Alternatives mentioned in the hpc-index.html file?

  3. What's the difference between bold and non-bold lines in the report for a specific module? RWH books says 'we see the actual source of the program, marked up in bold yellow for code that wasn't tested, and code that was executed simply bold.' What about those lines that not bolded? How do they impact the test coverage report?

  4. I see a lot of yellow highlights for things like deriving (Show) -- the Show is highlighted. I am not sure how this impacts the test coverage report. I derive them so I can print them out and debug during development. Is it recommended that I remove them in the final code before testing? I want to get a pretty accurate view and don't want these non-evaluated expressions to impact it.

In my module that declares most of the custom types for persistent, I have something like (I know I can use `FromJSON, etc. in deriving and I have it like below because I sometimes manually create a json object so easy to add):

data CustomType = Manual | Auto deriving (Show, Eq, Generic) instance FromJSON CustomType instance ToJSON CustomType derivePersistField "CustomType"

The hpc report has data and instance lines as non-bold (#3 above) and only derivePersistField is bolded. It says 40 covered out of a totalof 90 or so -- which indicates poor coverage. Most of these things are data / instance declarations. Should I be doing something else to get better coverage? If these are fine, how do I ignore them so the report gives a realistic picture? (Note: I am converting them To & From JSON frequently in app and those end points are being tested)

Many data fields were created mainly to send back JSON. I put some values in them and return them to the client. In the HPC report, it has flagged many of the fields within my record as 'never been called' -- it is a bit puzzling to me as wouldn't they be called at the time of creating the JSON? For example: Validation messages are being sent to the client and I have a declaration that looks like:

data ValidationError = ValidationError { field :: Text, message :: Text } deriving (Show, Generic) instance ToJSON ValidationError

I see yellow highlights for field and message. I am getting back validation errors in my client. Why would these fields be never called. I set them and call toJSON but I would expect the JSON call will access the fields?

Appreciate your help.

submitted by ecognium
[link] [2 comments]
Categories: Incoming News

Instead of a kitchen sink language Haskell should be expressed as a base language and customizations of that language

Haskell on Reddit - Thu, 08/20/2015 - 11:39am

The base language might look something like

type Var = String data Core = ModuleName String | Exports [Export] | Imports [Import] | Decls [Decl] ... type Decl = Data | Fun Var Expression | TypeSig Var Type ... data Expression = Case ... | LetVar Var Expression | Lambda Var Expression ...

An example of a core program might look like

module Foo where exports fooBar imports System.IO (...) Data.String (...) Data.Bool (...) fooBar = \happy -> case happy of True -> putStrLn "hello" False -> putStrLn "go away"

Then we could express all sorts of expansions to the base language. the PatternBindings extension would allow us to use pattern bindings instead of just binding to a var. The IfThenElse extension would allow the use of 'if' instead of 'case'. The Do extension introduces the obivous. Type classes would be introduced by the TypeClasses extension.

In addition to extensions we would also have "flavours". A flavour is just a known collection of base extensions and alternative extensions. So for example we could have

flavour Haskell98 builtin98 avail98 builtin98 = [IfThenElse, Do, PatternBindings] avail98 = [RankNTypes, TypeClasses] flavour Haskell2010 builtin2010 avail2010 builtin2010 = [Haskell98, GADTs, ...] avail2010 = [TupleSections, MultiwayIf, ...]

The yearly language standardization process would consist of collecting extension proposals and deciding what will be considered builtin for that year, or just available. Then effort is made to ensure that the accepted extensions all play well together.

The advantages of this approach would be having a well-factored language and reducing standardization stalls.

EDIT:

I have simplified my thinking. A flavour is just a set of compatible extensions.

And to further this idea of giving a more abstract description of haskell-like languages. We would write the standard something like follows

A haskell-like language should have a way to Define a module Declare exports Create a type class Declare a datatype Declare a type alias Give a type signature Define a function Declare the fixity of a function Give an expression Bind expressions to variables Pattern match on an expression haskell-like language there are expressions like the following numbers lists characters strings bools btyes ... arithmetic logical operations lambda

We would also give rules regarding the semantics of haskell-like languages and express them with Core.

We would have extensions. For example, PatternBindings and FunctionClauses and a LetPatterns extension that depends on those two extensions. With these extensions we have the syntax for let and the current way of defining functions and have specified a portion of the syntax of haskell98.

We would also use extensions to mark to changes in semantics.

submitted by zandekar
[link] [17 comments]
Categories: Incoming News

How to parse a Maybe String into a Maybe Int?

Haskell on Reddit - Thu, 08/20/2015 - 11:07am

This is probably a very newbie question, but I googled for over an hour to no avail.

I am trying to parse an optional command line argument (Maybe String) into a field in a record of type Maybe Int. I apparently have no idea how to do this without getting an error. I've tried things like this:

(\arg opt -> return opt { pass = fromMaybe Nothing arg })

But that throws an error:

Couldn't match type ‘[Char]’ with ‘Maybe Int’ Expected type: Maybe (Maybe Int) Actual type: Maybe String In the second argument of ‘fromMaybe’, namely ‘arg’

I hate coming to reddit begging for an answer but I'm rather stuck (and I'm less likely to get downvoted here than on StackOverflow).

submitted by NeuroXc
[link] [25 comments]
Categories: Incoming News

Publish-suscribe variables

Haskell on Reddit - Thu, 08/20/2015 - 11:02am
Categories: Incoming News

haddock complains about unknown symbol in .a file

haskell-cafe - Thu, 08/20/2015 - 7:47am
Dear all, what is happening here? http://hackage.haskell.org/package/satchmo-2.9.9.1/reports/1/log The library is built, but haddock fails with haddock: /home/builder/hackage-server/build-cache/tmp-install/lib/x86_64-linux-ghc-7.8.3/minisat-0.1.2/libHSminisat-0.1.2.a: unknown symbol `_ZGVZN7Minisat6Option13getOptionListEvE7options' Why is haddock complaining, but ghc is not? Any pointers appreciated (to explain and solve the problem - I think there's a work-around of uploading documentation to hackage but that does not feel right) - J.W.
Categories: Offsite Discussion

Imperative bits of Haskell

Haskell on Reddit - Thu, 08/20/2015 - 7:13am
Categories: Incoming News

List of nitpicks

haskell-cafe - Thu, 08/20/2015 - 6:30am
Hello all, Inspired by the recent thread re. modifying data/type/newtype syntax, I've made a wiki article dedicated to Haskell-related nitpicks. I've added a few entries; one from the thread I just mentioned, and a classic from way back in the 90s (map vs fmap). https://wiki.haskell.org/Nitpicks Hopefully, this page will help us keep track of what people are annoyed about (especially people who aren't already inured to the quirks of Haskell) as well as give us inspiration for future proposals. Cheers, Will _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Haskell developer position in Jerusalem

haskell-cafe - Thu, 08/20/2015 - 1:01am
We have a position open for a Haskell developer. This is an on-site position at our development center in Jerusalem. You will be working on our enterprise customer-tailored content delivery products - see the "Products" tab on our home page - which are implemented (mostly) in Haskell. Search for Haskell on our "Careers" page for a fuller description of the position. Submit your CV to [jobs< at >suite-sol.com](mailto:jobs< at >suite-sol.com), but also feel free to contact me if you have any questions. Thanks, Yitz
Categories: Offsite Discussion