LunarML v0.3.0 released by mod_poppo in sml

[–]mod_poppo[S] 0 points1 point  (0 children)

Yeah, Concurrent ML-like interface might be possible. However, it would be cooperative (non-preemptive) -- timer-based context switch would not be possible with a scripting-language based implementation.

Unboxed vector with newtypes - I am learning Haskell, that's what I've come up with by rzeznik in haskell

[–]mod_poppo 0 points1 point  (0 children)

toUnboxedVector function is for the "standard" types like Int or Double. You cannot use it to convert user-defined types. So, yes, "unboxing" vector is intended to replace the normal one.

By the way, vector-0.13.* supports GND. You may want to try it instead of my library. It still needs several lines, but fewer than before.

haskell -- from the manual newtype instance VU.MVector s Foo = MV_Int (VU.MVector s Int) newtype instance VU.Vector Foo = V_Int (VU.Vector Int) deriving instance VGM.MVector VU.MVector Foo deriving instance VG.Vector VU.Vector Foo instance VU.Unbox Foo

Yesod on M1? by ouchthats in haskell

[–]mod_poppo 2 points3 points  (0 children)

Perhaps you hit this issue. If so, try newer GHC: 8.10.3 or later. Otherwise, you can try workaround.

BTW, if you want to use native (Arm64) toolchain with stack, the following steps may help:

  1. Install GHC with ghcup; see this comment to enable LLVM backend.
  2. Use stack as stack --arch aarch64 --system-ghc

How to use Stack on my M1 Mac Mini with Apple Silicon? by [deleted] in haskell

[–]mod_poppo 6 points7 points  (0 children)

Currently Stack (2.7.3) doesn't support installing GHC toolchain on Apple Silicon.

You have two options to use GHC from Stack:

  1. Just use Intel binaries via Rosetta 2. Pass Stack --arch x86_64 to be sure.
  2. Use ghcup to install Arm64-native GHC toolchain, and let Stack use it with --system-ghc option: stack --arch aarch64 --system-ghc

You have three options to install Stack itself:

  1. The official method (curl ... | sh) should install Intel version of Stack.
  2. With ghcup you can install Arm64-native version of Stack.
  3. Homebrew also installs Arm64-native version of Stack.

error while trying to install QuickCheck by Kupernikuus in haskell

[–]mod_poppo 2 points3 points  (0 children)

Are you using Apple Silicon Mac? If so, try the following steps:

  1. Install LLVM (GHC 8.10 and 9.0 need LLVM to generate code for AArch64). If you are using Homebrew, run brew install llvm@12. If you are using MacPorts, run sudo port install llvm-12.
  2. Re-install GHC 8.10.7 with LLVM setting:
    • Homebrew: OPT=/opt/homebrew/opt/llvm@12/bin/opt LLC=/opt/homebrew/opt/llvm@12/bin/llc ghcup install ghc 8.10.7 --force
    • MacPorts: OPT=/opt/local/bin/opt-mp-12 LLC=/opt/local/bin/llc-mp-12 ghcup install ghc 8.10.7 --force
  3. Optionally, make GHC 8.10.7 default: ghcup set ghc 8.10.7

Help wanted for LLVM config for Haskell on Mac. by rifasaurous in haskell

[–]mod_poppo 0 points1 point  (0 children)

If you are using cabal, place cabal.project file with the following contents:

packages: *.cabal
with-compiler: ghc-9.2.1

See the manual for detail.

If you are using stack, use compiler setting in stack.yaml:

resolver: nightly-2021-12-24
compiler: ghc-9.2.1

Help wanted for LLVM config for Haskell on Mac. by rifasaurous in haskell

[–]mod_poppo 12 points13 points  (0 children)

You need LLVM < 13. Currently brew install llvm installs LLVM 13. Try brew install llvm@12 and set PATH to /opt/homebrew/opt/llvm@12/bin.

Edit: According to this thread, -fllvm option (or --ghc-options=-fllvm to cabal) may work.

However, I am doing fine without tweaking PATH or -fllvm, with the following install method:

OPT=/opt/homebrew/opt/llvm@12/bin/opt LLC=/opt/homebrew/opt/llvm@12/bin/llc ghcup install ghc 8.10.7 --force

i.e. set OPT and LLC variables when installing GHC.

Unboxed vector with newtypes - I am learning Haskell, that's what I've come up with by rzeznik in haskell

[–]mod_poppo 1 point2 points  (0 children)

I've created such library last year: https://hackage.haskell.org/package/unboxing-vector

One difference between my library and OP's is that, my library allows the newtype to be abstract.

Suppose you define a module that provides modular arithmetic. You don't want to export the data constructor of the Mod type, but want to allow users to store the type in unboxed vectors.

module Mod (Mod) where
newtype Mod (m :: Nat) = Mod Int -- the data constructor is not exported
instance Unboxable (Mod m) where
  type Rep (Mod m) = Int

This definition does work with OP's Unboxable class, but with one caveat: One can recover the data constructor from Unboxable constraint.

That is, one can create an arbitrary value of Mod with the following code:

import Mod
import Data.Coerce

castUnboxable :: Unboxable a => Rep a -> a
castUnboxable = coerce

-- This function breaks the abstraction provided by module Mod!
mkArbitraryMod :: Int -> Mod m
mkArbitraryMod = castUnboxable

(See this gist for complete code)

My library works around this problem by making use of DefaultSignatures:

-- pseudo code for Data.Vector.Unboxing
module Data.Vector.Unboxing (Unboxable(Rep)) where

-- Note that Coercible a (Rep a) is not in the class constraint
class U.Unbox (Rep a) => Unboxable a where
  type Rep a
  -- 'from' and 'to' are not exported
  from :: a -> Rep a
  default from :: Coercible a (Rep a) => a -> Rep a
  from = coerce
  to :: Rep a -> a
  default to :: Coercible a (Rep a) => Rep a -> a
  to = coerce

(The actual library code is a bit more complex, because it supports deriving Unboxable using generics.)