Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

Discussion about hnix #24

Closed
CMCDragonkai opened this issue May 16, 2018 · 5 comments
Closed

Discussion about hnix #24

CMCDragonkai opened this issue May 16, 2018 · 5 comments

Comments

@CMCDragonkai
Copy link
Member

hnix (https://github.com/haskell-nix/hnix) is a Haskell re-implementation of the Nix language.

This can be useful for artifact bindings when binding to Nix artifacts.

It is also useful as a foundation to write the Architect language parser and compiler.

@CMCDragonkai
Copy link
Member Author

First thing I discovered is that hnix has Nix's expressions defined in https://github.com/haskell-nix/hnix/blob/master/src/Nix/Expr/Types.hs

Specifically: https://github.com/haskell-nix/hnix/blob/738ef09bf9add0f0f21d7a72dd5ce31dbd200f67/src/Nix/Expr/Types.hs#L93-L140

The comments mention that this data type is polymorphic in order to make use of Functor and other typeclasses. This is an interesting pattern called the type-level Fix pattern. It is explained here: http://mainisusuallyafunction.blogspot.com.au/2010/12/type-level-fix-and-generic-folds.html and https://www.schoolofhaskell.com/user/bartosz/understanding-algebras

Later:

https://github.com/haskell-nix/hnix/blob/738ef09bf9add0f0f21d7a72dd5ce31dbd200f67/src/Nix/Expr/Types.hs#L172-L173

I believe this is just done to make the Nix expression algebraic data type to be more generic so they can use generic higher order functions like fmap and other things to work with the abstract evaluation tree.

@CMCDragonkai
Copy link
Member Author

A nix atom is something that evaluates to themselves. They are the "literals". These are defined here: https://github.com/haskell-nix/hnix/blob/738ef09bf9add0f0f21d7a72dd5ce31dbd200f67/src/Nix/Atoms.hs#L18-L32

These atoms include only ints, floats, booleans and null.

@CMCDragonkai
Copy link
Member Author

Note that Nix is an dynamically/unityped language. So the Types.hs used in hnix don't mean Nix types, but the algebraic data types used to represent Nix constructs for the hnix compiler/evaluator to deal with.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented May 16, 2018

Should find out what all the strictness used in constructors for.

This commit added in the strictness annotations haskell-nix/hnix@77bc4cb

With the comment that while it doesn't improve speed, it appears to reduce memory usage. For further reference: http://blog.johantibell.com/2011/06/memory-footprints-of-some-common-data.html

@CMCDragonkai
Copy link
Member Author

Continuing integration into hnix here: MatrixAI/Architect#14

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant